Have an input of type="file" which triggers this function:
function DoUpload(files) {
var reader = new FileReader();
reader.onload = function (e) {
var data = {
file: e.target.result,
extension: file.name.substr(file.name.lastIndexOf("."))
};
$.ajax({
headers: {
"X-RequestDigest": $("#__REQUESTDIGEST").val()
},
url: "{baseurl}" + "http://ift.tt/1BMmLtZ",
contentType: "application/json",
data: JSON.stringify(data),
dataType: 'json',
type: "POST",
success: function (response: ITempDocumentInfo) {
dfd.resolve();
},
error: function (e) {
console.error(e);
}
});
};
reader.readAsArrayBuffer(file);
}
The service lives in SharePoint and looks like this:
[WebService(Namespace = "http://www.blah.com/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
[System.Web.Script.Services.ScriptService]
public class FileInfo : System.Web.Services.WebService
{
[WebMethod(EnableSession = true)]
public TempDocumentInfo AddScannedItem(string instanceId, string uri, string itemKey, string data, string extension)
{
byte[] bytes = new byte[data.Length * sizeof(char)];
System.Buffer.BlockCopy(data.ToCharArray(), 0, bytes, 0, bytes.Length);
var stream = new MemoryStream(bytes);
.
.
.
}
}
Once I have the data in C#, I cannot seem to be able to be able to do anything with it. For example. Uploading and processing a bmp image throws an exception:
var blah = System.Windows
.Media
.Imaging
.BmpBitmapDecoder
.Create(stream,
BitmapCreateOptions.PreservePixelFormat,
BitmapCacheOption.None);
Am I not generating the AJAX request correctly?
Aucun commentaire:
Enregistrer un commentaire