L
L
les212015-01-21 12:42:33
JavaScript
les21, 2015-01-21 12:42:33

How to upload a file to yandex disk from a Javascript application and the fileupload plugin?

Good afternoon. Ask for advice from Javascript developers.
I am trying to upload a file from my application. Written in Oracle mod_plsql + Javascript (JQuery). To upload files, I use the
jquery fileupload plugin,
which should support cross domain upload
https://github.com/blueimp/jQuery-File-Upload/wiki...
But when generating a request, it inserts origin, which violates the requirements of api yandex disk
"Uploading a file to the received URL The file must be PUTted to the download URL within 30 minutes of receiving this URL (after 30 minutes the link will stop working and will need to be re-requested). Uploading a file to the store does not require an OAuth token. Note: The request should not specify the Origin header.In general, a request with a non-empty Origin API responds with HTTP code 500. "
Please help me how to solve this problem
The example itself (in the example, part of the token was slightly lost)
I get the path
var _formData;
varformURL;
$.ajax({
url: " https://cloud-api.yandex.net/v1/disk/resources/upl... ",
async: false,
dataType: "json",
type: 'get',
beforeSend: function(xhr) {
xhr.setRequestHeader('Authorization', 'OAuth 8317f5afab3e4a0fa1610bd59d57');
},
success: function(result) {
formURL = result.href;
},
error: function (xhr, ajaxOptions, thrownError) {
alert(xhr.status+' '+thrownError);
}
});
The request successfully completed, I got something like
" https://uploader18h.disk.yandex.net:443/upload-tar... "
I hang the handler on the standard file selection
$("#yd").fileupload({
forceIframeTransport : true,
type: "PUT",
url: formURL,
beforeSend:
done: function (e, data) {
null;
},
fail: function (e, data) {
alert(data.jqXHR.status+' '+data.errorThrown);
}
});
But when I select a file, I get an error
jquery-1.8.3.js:8434 OPTIONS https://uploader18h.disk.yandex.net/upload-target/...
(index):1 XMLHttpRequest cannot load https:// uploader18h.disk.yandex.net/upload-target/... No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin ' alcides.fors.ru:802 ' is therefore not allowed access. The response had HTTP status code 500.
Tried to overwrite origin, but it doesn't
work beforeSend: function(xhr) {
xhr.setRequestHeader('Origin', formURL);
},
Well, that's all, I ask for advice on how to upload files to yandex disk
Thank you

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question