我正在使用 Force.com Apex 和 VF,试图利用 Cloudinary 进行一些内容管理。我在 Chrome 中遇到了以下问题(不知道为什么它显示“未定义”,因为云名称是在 JS 中定义的):
POST https://api.cloudinary.com/v1_1/undefined/upload 401 (Unauthorized) ...... api.cloudinary.com/v1_1/undefined/upload:1
在沮丧的时候真的很感激任何帮助。这是代码(注意注释):
- 顶点
:
public String getCldSig() {
Datetime d = datetime.now();
Long uxtime = d.getTime() / 1000; //method provides epoch/unix time
String apisec = '<some_secret>';
String serial = 'callback=<some_url>&public_id=<some_id>×tamp=' + uxtime + apisec;
Blob sha = Crypto.generateDigest('SHA1', Blob.valueOf(serial));
String sig = EncodingUtil.convertToHex(sha); //perhaps I need to do UTF-8
String jsoSerial = '{"public_id":"<some_Id>",';
jsoSerial += '"timestamp":"'+ uxtime + '",';
jsoSerial += '"callback":"<some_url>",'; //maybe an issue with hosting the CORS html on a VF page.
jsoSerial += '"signature":"' + sig + '",';
jsoSerial += '"api_key":"<some_key>"}';
return jsoSerial.escapeHtml3(); //seems to be the right escape output HTML
}
Javascript/jQuery:
$.cloudinary.config({"api_key":"<some_key>", "cloud_name":"<some_id>"}); $('.cloudinary-fileupload') .fileupload({ dropZone: ".sceneUpBtn", progress: function (e, data) { $(".progress").text("Uploading... " + Math.round((data.loaded * 100.0) / data.total) + "%"); } }); $('.cloudinary-fileupload').bind('fileuploadstart', function(e){ $('.sceneUpPrev').html('Upload started...'); }); $('.cloudinary-fileupload').bind('fileuploadfail', function(e){ $('.sceneUpPrev').html($.cloudinary.error); //**due to lack of documentation don't know how to get any specific error message using the jQuery library. Would expect messages similar to AWS S3 }); $('.cloudinary-fileupload').bind('cloudinarydone', function(e, data) { $('.sceneUpPrev').html( $.cloudinary.image(data.result.public_id, { format: data.result.format, version: data.result.version, crop: 'scale', width: 200 })); $('.image_public_id').val(data.result.public_id); return true; });
输入 HTML:
<input class="cloudinary-fileupload"
data-cloudinary-field="upref"
data-form-data=""public_id":"<some_id>","timestamp":"1372282433","callback":"<some_url>","signature":"<some_sig>","api_key":"<some_key>"}"
id="sceneUpload"
name="file"
type="file">