Some solutions for uploading videos to seven kn

Source: Internet
Author: User

     <Divclass= "Form-group">                <label>Upload Video:</label>                <Divclass= "My-upload">                    <Divclass="">                        <inputtype= "File"ID= "FileUpload"name= "FileUpload"class="" />                    </Div>                </Div>            </Div>                      <Divstyle= "padding-top:30px; padding-left:283px;">                <Videosrc= "@Html. Valuefor (c = c.vediolink)"ID= "Vediofile"style= "width:400px;height:250px;"Controls= "Controls">                </Video>            </Div>@Html. hiddenfor (c = c.vediolink, new {@id = "vedio"})<spanstyle= "margin-left:20%;"ID= "Progress" >Upload progress: 0%</span>
<Script>   //Upload Video    $('Input[name=fileupload]'). Change (function () {        //Console.log ("in It");layer.msg ('Upload video ... Please do not close or refresh the page ...')        varFormData= NewFormData ($ ("#uploadForm")[0]); varXHR= NewXMLHttpRequest (); varURL= "/console/uploadvedio/indexs"; Xhr.open ("POST", URLs,true); Xhr.onreadystatechange= function () {            if(Xhr.readystate== 4 &&Xhr.status==  $) {console.log (xhr.responsetext); varReturndata=Eval ("(" +Xhr.responsetext+ ")");                Console.log (Returndata.datas); if(Returndata.status== 1) {layer.msg (returndata.msg); } Else{layer.msg (returndata.msg); $("#vediofile"). attr ('src', Returndata.datas) $ ("#vediofile2"). attr ('src', Returndata.datas) $ ("#vedio"). Val (Returndata.datas);        }            }        }; //Progress bar Sectionxhr.upload.onprogress= function(evt) {if(evt.lengthcomputable) {varPercentComplete=Math.Round (evt.loaded*  - /evt.total); if(PercentComplete== -) {document.getElementById ('Progress'). InnerHTML= "Upload Progress Complete! Do not close and refresh the page until the upload is successful. "; } Else{document.getElementById ('Progress'). InnerHTML= "Upload progress:" +PercentComplete+ "%"; }                          }        };    Xhr.send (FormData); });</Script>

The video is uploaded using XMLHttpRequest.

Use XMLHttpRequest. upload.onprogress to display upload progress

Receive code in the background

[HttpPost] PublicActionResult Indexs (formcollection collection) {HttpPostedFileBase file= httpcontext.request.files[0]; if(File! =NULL)            {                if(file. Filename.length >2&& Filename.tolower (). IndexOf (". mp4") <0)                {                    returnWriteerror ("please upload. MP4 Formatted Videos"); }            }            stringFileName = GetFileName (file. FileName);//GetFileName ();            stringSavename = DateTime.Now.ToString ("yyyymmddhhmmssffff") +FileName; stringPlayfile = Server.MapPath (Publicmethod.upfile +savename); stringUpfilename = Publicmethod.upfile +Savename; //upload video to localfile.            SaveAs (Playfile); //upload video to seven knQiniufun.        Putfile (Qiniufun.qnspace, Qiniufun.fullname (Upfilename), Server.MapPath (Upfilename)); }         Public stringGetFileName (stringfileName) {            inti = Filename.lastindexof ("\\") +1; stringName =filename.substring (i); returnName; }

The following issues occurred during the upload to seven kn

1. Use normal upload mode to upload only the file size within 100M of the video

Speaking of which, we're going to throw a notch. Seven KN SDK, the example code method names and methods on the DLL and official documents downloaded from NuGet are not available.

2. The uploaded video cannot be played on both the PC side and the phone

For the above question seven cows have a little trick to see the encoding of the video

http://7xo9nf.com2.z0.glb.qiniucdn.com/test.mp4?avinfo//Video address +? Avinfo

Solution: Use the Format factory to change the video encoding to AVC (H262) or ACV (H264) encoding

All right, after solving the above problems, we find that publishing the code to the IIS Environment Code has the following problems

1.mp4 formatted file IIS is not recognized

Add the MIME type of the video. MP4 Video/mp4

2. Uploading folder access permissions issues

3.iis Upload File size limit

Select site Home-"Request Filter-" Edit feature Settings-"Set allow maximum content length

4. Time limit for requests

Webconfig Settings and XMLHttpRequest settings

Some solutions for uploading videos to seven kn

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.