2013-04-15 33 views
1

我試圖使用Trigger.io將照片上傳到Appcelerator雲服務(ACS)存儲。使用Trigger.io將照片上傳到Appcelerator ACS

我找不出用於文件對象的正確語法。 我得到一個錯誤「錯誤:語法錯誤,無法識別的表達式:#[對象的對象]」

這裏是我的相關代碼:

$("#photograph-record").on("click", function(){ 
    forge.file.getImage({source:"camera", width: 280, height: 280},function(file) { 

    var data = { 
      photo: file //the ID of file input control 
     }; 

    sdk.sendRequest('photos/create.json', 'POST', data, callback); 
    }); 
}); 

這裏的文檔的ACS照片類 - http://cloud.appcelerator.com/docs/api/v1/photos/create

必要參數 - 圖片:附加的二進制文件

因爲它需要一個二進制我試過「照片:forge.file.string(文件)」(http://docs.trigger.io/en/v1.4/modules/file.html#modules-file),但在Appcelerator的一側有一個錯誤「照片對照片上傳所需儀表「。

我沒有問題使用forge.file.url將圖像傳入我的應用程序頁面視圖,所以我知道這個文件對象沒有問題,它只是找出正確的語法將它作爲二進制傳遞給sdk .sendRequest調用。

有關我需要傳遞數據變量以實現此功能的任何想法?

回答

1

Appcelerator文檔在這裏相當不錯 - 它看起來像是期待一個名爲photo的POST參數,其中包含二進制圖像數據。

要做到這一點用我們request module

$("#photograph-record").on("click", function(){ 
    forge.file.getImage({source:"camera", width: 280, height: 280},function(file) { 
     file.name = 'photo'; // the magic  
     forge.request.ajax({ 
      url: 'https://api.cloud.appcelerator.com/v1/photos/create.json', 
      files: [file], 
      success: function() { ... }, 
      error: function() { ... } 
     }); 
    }); 
}); 

我不明白的方式在這裏用自己的JS庫,因爲他們期待着你的HTML表單元素的id傳遞給獲得數據,但我們直接與相機或畫廊進行交互...

+0

謝謝詹姆斯,我會試試看看它是如何發展的。 我只需要弄清楚用forge.request.ajax調用傳遞我的ACS憑證的正確方法。 希望它就像REST調用一樣:https://api.cloud.appcelerator.com/v1/photos/create.json?key= lawlessmedia

+1

終於明白了。必須將session_id添加到URL以驗證用戶並添加POST類型。 'forge.request.ajax({ \t \t URL:「https://api.cloud.appcelerator.com/v1/photos/create.json?key=app_key_goes_here&_session_id=session_key_goes_here, \t \t類型: 'POST', \t \t文件:[文件], \t \t成功:函數(){警報( '成功');}, \t \t錯誤:功能(數據){警報( '錯誤' + data.content);} \t \t});' – lawlessmedia