Uploading Documents to SP 2013 with jQuery and REST work just fine (Properties when uploading Files using REST in SP 2013) but these methods require a HTML5 compatible browser. The problem is now I also have to target older browsers.
I found a nice jQuery Plugin (https://github.com/blueimp/jQuery-File-Upload) which looks very promising and should do the job. e.g. wrapping in an iframe for older browsers. So I configured it the same as previously but it does not work. I guess you have to provide data
as a base64 encoded arraybuffer when using REST. Is there a way to upload a file (can also be witouth REST) to a DocLib, ideally with this plugin?
Configuration:
function initializeUploader() {
// Init Uploader
$('#fileInput').fileupload({
dataType: 'json',
url: getRESTUrl(),
headers: {
"accept": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val()
},
add: function (e, data) {
data.context = $('#SubmitButton').val('Start Upload')
.click(function () {
//url = getRESTUrl();
data.context = $('<p/>').text('Uploading...').replaceAll($(this));
data.submit();
});
},
done: function (e, data) {
data.context.text("upload finished");
},
fail: function (e, data) {
data.context.text("upload failed");
}
});
function getRESTUrl() {
var serverurl = SPWeb.get_serverRelativeUrl() + "/Lists/TestDocLib";
var targetRESTUrl = _spPageContextInfo.webServerRelativeUrl +
"/_api/web/GetFolderByServerRelativeUrl('" + serverurl + "')/Files" +
"/Add(url='testfile.png',overwrite=true)";
return targetRESTUrl;
}
Errors I receive in the LOGS:
SPRequest.PutFile: UserPrincipalName=[...], AppPrincipalName= ,bstrUrl=http://{myweb} ,bstrWebRelativeUrl=Lists/TestDocLib/testfile.png ,cbFile=38862 ,punkSPFileMgr= ,punkFFM= ,PutFileOpt=1 [...]
System.IO.DirectoryNotFoundException: 0x80070003There is no file with URL 'http://{site}/Lists/TestDocLib/testfile.png' in this Web., StackTrace:
I don't know why SP (obivously) wants to retrieve the file. Previously I also had to specify the target filename and it just worked fine.