actionscript 3 - as3 file download restrain? -


I have a flash download on my site to download a PDF file.

  Var myfileReference: FileReference = New FileReference (); Down_mc.visible = false; Down_comp.visible = false; Var myRequest: URLRequest = New URLRequest ("GEORGIA INCORPORATED.pdf"); MyfileReference.addEventListener (IOErrorEvent.IO_ERROR, ioError); Output_txt.text = ""; Function ioError (Event: ErrorEvent): Zero {output_txt.text = "Sorry IO Error During Downloading File Error:" + "\ n" + Event; } MyfileReference.addEventListener (ProgressEngine.progress, file download progress); Function fileDownload Progression (Event: Progressive Event): Zero {down_mc.visible = true; } MyfileReference.addEventListener (event.complete, file download complete); Download the Function File (Completed: Event): Zero {down_mc.visible = false; Down_comp.visible = true; } Function Download File (Event: Mouse Event): Zero {try {myfileReference.download (myRequest); } Error (Error: SecurityAir) {Error downloading: "+" \ n "+ error;} Catch (error: invalid operation error) {error is downloading:" + "\ n" + Error; }} B1.addEventListener (MouseEvent.CLICK, downloadFile);   

The problem is that some people want to change the file name they are downloading and also change the extension, .pdf, thus making the file unusable. What is a way to stop customers from changing extensions?

In pure as3, you can not force the user to save a file under a specific extension The only way to do this is to use the air so that you can control it through the filestream object (you can choose the name of the file).

If you want to air it, you can:

  // Assume that you get raw data of your pd var pdfData: ByteArray; Var f: file = file. Descope Dirdieri .resolvePath ("myPdf.pdf"); // When the user selects a file, f.addEventListener (Event.SELECT, function (E: Event): Zero {var targetFile: File = as e.target file; // Check that the selected file has a pdf extension If (targetFile .bn.svast (targetFile.nativePath.length - 4)! = ".pdf") // If not, then add it to targetFile = Add new file (targetFile.nativePath + ".pdf"); // file Save var fs: FileStream = new filestream (); FSSPEN (TargetFile, FlamemadeWright); FasaliteBits (PDFData); FSLOS ();}); // Ask user to save a file (user by default on desktop) f.browseForSave ("Save PDF");    

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -