Hi,
I've a problem with my app, i'm beginner and i would like to upload my images on Google Drive :
1 - The authentication is good 2 - The problem is in the mime Type, i think
This is the function, i use for try to upload in my G-Drive
[CODE] function upLoadFile(myAccessToken, myFileName, blobData) {
var base64image = Ti.Utils.base64encode(blobData); //convert blob to base64 encoded string
var reqBody = '--foo_bar_baz\nContent-Type: application/json; charset=UTF-8\n\n{"title": "' + myFileName+".jpg" + '"}\n--foo_bar_baz\nContent-Type: image/jpeg\nContent-Transfer-Encoding: base64\n\n' + base64image + '\n--foo_bar_baz--';
var url = "https://www.googleapis.com/upload/drive/v2/files";
var client = Ti.Network.createHTTPClient({
onload : function(e) {
//Ti.API.info("Received text: " + this.responseText);
alert('Fichier : '+myFileName+' ok');
},
onerror : function(e) {
//Ti.API.debug(e.error);
alert('error');
},
timeout : 100000000
});
client.open("POST", url);
client.setRequestHeader('Authorization', "Bearer " + myAccessToken);
client.setRequestHeader('Content-Type', 'multipart/related; boundary="foo_bar_baz"' );
client.send(reqBody);
} [/CODE]
And this is the loop , to get the file in my app
[CODE] $.move.addEventListener('click', function(e) {
/* Pour Parcourir ANDROID pas IOS */
var dir = Titanium.Filesystem.getFile(Titanium.Filesystem.externalStorageDirectory);
Ti.API.info('FICHIER : '+dir);
googleAuth.isAuthorized(function()
{
var contents = dir.getDirectoryListing();
for(var content in contents)
{
Ti.API.info(contents[content]);
var blob = contents[content].read();
Ti.API.info("Blob ? "+blob);
}
},
function()
{
googleAuth.authorize();
});
}); [/CODE]
The function need a blob, but there is something wrong... if someone can help me...
Best Regards