简体   繁体   中英

Create and write to a file with javascript

On the client side I want to:

  1. Generate random data up to a specified size (ex: 1Mb or 512Kb).

  2. Write that data into a file.

  3. Post that file to an endpoint on my server with an AJAX request.

I know #1 is possible, but I'm not sure how to do it. I'm not sure if #2 is possible; I've heard that Chrome currently supports the full HTML5 file API, but I need a solution that works on mobile browsers too (iOS Safari, Android, etc). #3 is easy and I already know how to do it (I included it for clarity about what I'm trying to do).

I agree with with sending data with post, but if you really want to create a file and then send it, you should read this question:

How to give a Blob uploaded as FormData a file name?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM