Hi,
We are using below code snippet to download a file from sharepoint's document library. It works completely fine for the text files i.e. readme.txt. However when we try to open .docx file downloaded using the same code snippet it gives file type unsupported error. We have created hybrid HTML 5 phonegap application and testing it on Android platform. Please any help highly appriciated.
function GetFile(filePath) { console.log(filePath); var ajaxUrl='http://server/_api/web/GetFileByServerRelativeUrl(\'' + filePath + '\')/$value'; console.log(ajaxUrl); $.ajax({ url: ajaxUrl, type: "GET", data: "arrayBuffer", processData: false, complete: FileReceivedSuccess, error: FileReceivedError }); } function FileReceivedError(xData, status) { console.log('Error retriving file' + status) } function FileReceivedSuccess(xData, status) { console.log('File Retrived Success' + status) console.log('File Retrived Object' + xData.responseText) textData = xData.responseText; fileSystem.root.getFile("sampledoc.docx", {create: true, exclusive: false}, gotFileEntry, fail); } var fileSystem; var textData ; //var stringData = "No Data"; function fail(error) { console.log("fail() called"); console.log(error.code); } function gotFileWriter(writer) { console.log("gotFileWriter() called"); writer.onwriteend = function(evt) { console.log("contents of file now 'textData'"); // console.log("My Data : "+ stringData); }; writer.write(textData); } function gotFileEntry(fileEntry) { console.log("gotFileEntry() called"); fileEntry.createWriter(gotFileWriter, fail); } function onFSSuccess(fs) { console.log("onFSSuccess() called"); fileSystem = fs; } document.addEventListener("deviceready", onDeviceReady, false); function onDeviceReady() { console.log("onDeviceReady() called"); //request the persistent file system window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onFSSuccess, fail); }