0

I just successfully migrated my parse.com hosted app to parse-server based implementation hosted at heroku. I'm using cloudinary_parse module with parse cloud code to upload user's avatar pictures to cloudinary. Upon testing I found that the image upload is not working and returning error. Here's the sample code:

module.exports = {

  //endpoint exports
  sign_cloudinary_upload_request,
  photo_thumbnail_url,

};


/* Cloudinary Parse Module for image storage */ 
var cloudinary = require("../cloudinary");


/// The following lines install a beforeSave filter for the given field within the given object
var PHOTO_OBJECT_NAME = "Picture";
var VIDEO_OBJECT_NAME = "Video";
var CLOUDINARY_IDENTIFIER_FIELD_NAME = "cloudinaryIdentifier";

/**
 * The following declaration exposes a cloud code function that enables you
 * to sign a direct-upload request from your app. 
 * @note This function assumes no extra parameters are needed for the upload.
 * @note This function embeds the username in the cloudinary tags field and eagerly creates a thumbnail.
*/

function sign_cloudinary_upload_request(request, response) {

    if (!request.user) {
        response.error("Needs a user");
        return;
    }

    response.success(
        cloudinary.sign_upload_request({tags: request.user.getUsername()})
    );

}

/**
 * The following declaration exposes a cloud code function that enables you to get a 
 * thumbnail url for Cloudinary of a the Photo entity. 
 * Cloud-based image manipulation URLs can also be generated on the mobile apps based 
 * on the identifier returned when uploading a object using the beforeSaveFactory above.
 */

function photo_thumbnail_url(request, response) {

    if (!request.user) {
        response.error("Needs a user");
        return;
    }

    var query = new Parse.Query(PHOTO_OBJECT_NAME);
    query.get(request.params.objectId, {

    success: function(result) {

        response.success({
            url: cloudinary.url(result.get(CLOUDINARY_IDENTIFIER_FIELD_NAME), {crop: "fill", width: 150, height: 150})  
        });

      },
      error: function() {
        response.error("image lookup failed");
      }

 });

When sign_cloudinary_upload_request is called from the iOS app, the parse server throws the following error: Error: Cannot find module 'cloud/cloudinary/version' I have tried to change the path to:

var cloudinary = require("cloudinary");

but server throws: error: Uncaught internal server error. [TypeError: cloudinary.sign_upload_request is not a function] TypeError: cloudinary.sign_upload_request is not a function

If I try to change the path to following;

var cloudinary = require("cloud/cloudinary");

var cloudinary = require("./cloudinary");

var cloudinary = require("./cloud/cloudinary");

the server throws: Error: Cannot find module '../cloud/cloudinary' etc

user3404693
  • 555
  • 1
  • 8
  • 19
  • Hi , can you check if cloudinary module is in your parse-server package.json ? – Ran Hassid Aug 14 '16 at 04:42
  • Did you follow the setup instructions on the [GIT repository](https://github.com/cloudinary/cloudinary_parse)? Including all the folders structure requirements? How about the sample project - did it install successfully? – Nadav Ofir Aug 14 '16 at 14:16
  • Did you try using `path`: `var path = require('path'); var cloudinary = require(path.join(__dirname, '/cloudinary.js'));` – Mads Foli Bjerre Aug 26 '16 at 07:00

0 Answers0