The code I present does not give any errors but the files uploaded to our server can not be opened, for example pdf viewer reports "corrupt file" the excel reports "some file formats lost this corrrupto" but repairs and can open.
1) the application should compile a list of file name plus a checkbox for the user to select which files you want to keep and related to the project
2) When the user presses "save" must download the checked attachments from gmail and upload it to our server
$("input[name='chAdjuntos']:checked").each(function(index, element) {
var aValor = $(element).val().split(":");
var messageId = aValor[0];
var attachId = aValor[1];
var archivo = unescape(aValor[2]);
var mime = unescape(aValor[3]);
var userId = "me";
var request = gapi.client.gmail.users.messages.attachments.get({
'id': attachId,
'messageId': messageId,
'userId': userId
});
request.execute(function(attachment) {
var status = new createStatusbar();
status.setFileNameSize(archivo, attachment.size);
// replace base64 url safe characters
var attData = attachment.data.replace("-","+").replace("_","/");
// get arraybuffer
var attArray = base64DecToArr(attData).buffer;
// construct blob
var blob = new Blob([attArray], { type:mime })
// create formdata object and append blob and other data
var fd = new FormData();
fd.append("id", $(".resultado").attr("id"));
fd.append('blob', blob, archivo);
// post file with jquery
sendFileToServer(fd, status);
});
});
Thanks in advance.