我刚刚成功地将我的parse.com托管应用程序迁移到heroku托管的基于解析服务器的实现。我正在使用cloudinary_parse
模块和解析云代码将用户的头像图片上传到cloudinary。经过测试,我发现图片上传无效并返回错误。这是示例代码:
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");
}
});
从iOS应用调用sign_cloudinary_upload_request
时,解析服务器会抛出以下错误:Error: Cannot find module 'cloud/cloudinary/version'
我试图改变路径:
var cloudinary = require("cloudinary");
但服务器抛出:error: Uncaught internal server error. [TypeError: cloudinary.sign_upload_request is not a function] TypeError: cloudinary.sign_upload_request is not a function
如果我尝试将路径更改为以下内容;
var cloudinary = require("cloud/cloudinary");
var cloudinary = require("./cloudinary");
var cloudinary = require("./cloud/cloudinary");
服务器抛出:Error: Cannot find module '../cloud/cloudinary'
等