问题
I have a web page where user uploads a video file using html's "input type = file" tag, I am catching that uploaded video file in JavaScript function variable where it is coming as blob URL. "blob:https://www.myownsite.com:8080/2e8cfd32-abf2-4db3-b396-91f76cc3b40c". I am not able to save this blob URL in my system.
HTML code:
<input type="file" name="video_file_name" accept="video/*">
<input type="submit" value="Upload Video" id="customVideoSubmit">
<button onClick="postVideo();" id="customVideoSubmit" aria- hidden="true">Upload Video</button>
JavaScript code:
function postVideo(){
var blobURL = document.querySelector('video').src;
$.ajax({
type: 'POST',
url: 'https://myapplication.com',
data: { videoData : blobURL , mediafilename : fileName},
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: function() {
console.log("Video saved successfully.");
}
});
}
variable blobURL contains following blob URL, which plays video properly if I put this on a separate tab of that browser.
blob:https://www.myownsite.com:8080/2e8cfd32-abf2-4db3-b396-91f76cc3b40c
How can I save this blob video file in my system. I have tried number of JavaScript methods and also back end methods in my Perl code like?
Nothing worked though. Any help will be much appreciated.
回答1:
A Blob URL
s lifetime is tied to the document
where the Blob URL
is created. If the document
which created the Blob URL
is closed the previously created Blob URL
should be revoked, see 8.6. Lifetime of Blob URLs.
You can POST
the Blob
or File
object itself to server Trying to Pass ToDataURL with over 524288 bytes Using Input Type Text; or a FormData
object with File
set as value Sending FormData with a binary data by using jQuery AJAX; or data URI
representation of File
object to server Upload multiple image using AJAX, PHP and jQuery.
来源:https://stackoverflow.com/questions/46880339/cant-save-uploaded-videos-blob-url-at-the-backend-server-using-ajax-call