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">