Search code examples
javascriptiosparse-platformparse-serverparse-cloud-code

Is it advisable to upload files as parameter of Parse Cloud Code function?


I want to upload videos to parse server. Instead of saving the video file with the Parse iOS SDK's PFFile I upload the video to Parse Cloud Code as parameter:

PFCloud.callFunction(inBackground: "uploadVideo", withParameters: ["videoData": videoData]]) { (response, error) in
    ...
}

On the server side I save the file:

Parse.Cloud.define("uploadVideo", function(request, response) {

    var videoData = request.params.videoData;
    var videoFile = new Parse.File("video.mov", videoData, "video/mov");

    videoFile.save(null, {useMasterKey: true})
    .then(
        function() {
            response.success();
        }, 
        function(error) {
            response.error(error.message);
        }
    );
});

Is that good practice or are there any risks involved? E.g. what is the maximum data object size to be passed as Cloud Code parameter?


Solution

  • I decided to upload the file with PFFile and send the file object to the Cloud Code function as parameter. Unlike PfObject which cannot be passed as Cloud Code function parameter, PFFile can.

    The advantage is that PFFile has an upload progress callback to give an upload status feedback to the user.