You're looking at our questions archive. This question was last updated almost 3 years ago.

If you're looking for help, head over to the Parse Developers Google Group or check out the tag on Stack Overflow.

Help Google Group Stack Overflow

Solutions to upload to S3 through Cloud Code?

2 votes 1 answer 6.26k views almost 3 years ago

Hello, so, I think I have to go though S3 for two reasons (please correct me if I'm wrong and sorry if it sounds a stupid question):

  • 10MB upload limit
  • 10GB parse space

I'm thinking about setting up Cloud Code to allow uploads, however I would like to hear some opinion before diving in.

I guess there are different solutions:

  • Use a third party server, that will call cloud code once upload finishes
  • Use a simple s3 upload library in cloud code
  • Use AWS SDK in cloud code but requires heavy file editing
  • Use a third party server, called via cloud code that will send the binary for store

In the first scenario I guess I'll handle file uploads and the call back Parse and inform it about the file upload or create/update records at will, this should be doable.

In the second, third and fourth scenarios: is it possible to accept file uploads in cloud functions? Will they be killed after a certain amount of time if the client is not able to send all the data it needs?

I'm open to suggestions, thanks.

1 Answer


S3 allows you to direct upload from browser, I found a blog which teach people how to direct upload file to s3 from browser.

The article use RoR to show how it work, I just rewrite it using Parse cloud code and jquery file upload. You can check my code below.

Cloud code part:

var Crypto = require('crypto');
var Buffer = require('buffer').Buffer;

var accessKeyId = 'YOUR AWS ACCESSKEY';
var secret_key = 'YOUR AWS SECRETE KEY';
var bucket = 'YOUR BUCKET NAME';
var s3_uploader = {

Parse.Cloud.define("awsInfo", function(request, response) {
  var setting = s3_uploader[request.params.uploadType];
  var date = new Date();
  var keyValue = setting.key+request.params.bookId+"/"+request.params.uploadType+"_"+
  var result = {"key":keyValue,

function s3_upload_policy(acl) {
    var d = new Date();
    var policy = {"expiration":d.toISOString(),
                    ["starts-with","$key", "uploads/"],
                    {"success_action_status": "201"}
    var buf = new Buffer(JSON.stringify(policy),'utf8');
    var result = buf.toString('base64');

    return result;

function s3_upload_signature(acl) {
    return  Crypto.createHmac('sha1',secret_key).update(s3_upload_policy(acl)).digest('base64');

Website part(using coffeescript and jquery file upload)

            form = $(this)
                dropZone: form.find('#dropzone')
                autoUpload: true
                dataType: 'xml'
                add: (event, data)->
                    uploadType = form.parent().attr("id").split('input')[1].toLowerCase()
           'awsInfo', \
                        success: (result) -> 
                        error: (error) -> 
                            alert error.message

                # send: (e, data) -> 
                #     form.find('.progress').fadeIn()  

                progress: (e, data) -> 
                    percent = Math.round((e.loaded / * 100)
                    $('#upload-modal').find('.bar').css('width', percent + '%')

                fail: (e, data) -> 

                success: (data) -> 
                    url = $(data).find('Location').text()
                    if form.parent().attr('id') == 'inputScreenshots'
                        image = $($('#inputScreenshots img[src=""]')[0])
                    else if form.parent().attr('id') == 'inputPDF'

                done: (event, data) ->
                    $('#upload-modal').find('.bar').css('width', '0%')


I am not familiar with javascript, so the code are a little mess, but it works well for me. Note that I included a module called 'crypto', I don't find any document about this module in, I use this module because Parse team told me cloud code had this module... Hope they have more detail document about this.

Thanks mate, will look into this solution

- Kurado over 3 years ago

How can I do this, if I already have Parse.File?

- Ivan over 3 years ago