Hi guys, I am trying to post an image file to my rails backend server. But unfortunately I could not save the file to my server. Here is my code.
btnUploadFile.addEventListener("click", function(e){ var postData={ "send_message":{ "id":pickerValue, "message": textArea1.value, "photo": uploadImgView.image, "user_id": user_id } }; var url = APPLICATION_URL+"/url.json?auth_token="+auth_token; var ajaxCall = Ti.Network.createHTTPClient({ onload: function(e) { Ti.API.info(this.responseText); }, onerror: function(e) { // this function is called when an error occurs, including a timeout Ti.API.info(e.error); Ti.API.info(this.responseText); } }); ajaxCall.setRequestHeader("Content-Type", "application/json"); //ajaxCall.setRequestHeader("Content-Type", "multipart/form-data"); ajaxCall.setRequestHeader('Accept','application/json'); ajaxCall.setRequestHeader('charset','utf-8'); ajaxCall.open("POST", url); ajaxCall.send(JSON.stringify(postData)); });And here is the log
Processing by FeedbackController#create as JSON Parameters: {"{\"send_message\":{\"id\":\"3\",\"message\":\"Test image upload. \",\"photo\":{\"file\":{\"hidden\":false,\"nativePath\":\"content://media/extern al/images/media/1921\",\"writable\":false,\"executable\":false,\"parent\":null,\"readonly\":true,\"directoryListing\":null,\"size\":0,\"apiName\":\"Ti.Proxy\",\"name\ ":\"tia-1595633997.jpg\",\"symbolicLink\":false,\"bubbleParent\":true},\"nativePath\":\"file:///storage/emulated/0/Pictures/image/tia-1595633997.jpg\",\ "height\":2592,\"length\":574092,\"width\":1456,\"mimeType\":\"image/jpeg\",\"apiName\":\"Ti.Blob\",\"text\":null,\"type\":1,\"bubbleParent\":true},\"user_id\":13}}"= >nil, "auth_token"=>"VnFQWwQPkiPqMXHzjCLi"}
But when I try to save the image files along with the message from the text area. Null values for the image is getting saved in the table.
Thanks,
Varun Krishna. P