简体   繁体   中英

How can I get the size of a POST request in javascript?

Is there any way to get the size of a POST request in javascript? I want to check the size of a file before uploading it via ac# handler so I can tell the user to upload a smaller file.

Thanks in advance.

It's not possible for JavaScript to access details of a file on the users machine. There would be major security implications if this was possible.

You will need to upload the file and check its size at that stage. That is best practise anyway, as you shouldn't assume anything about your users environment. In this case they may not have JavaScript in the browser.

Short answer: no.

Long answer: Possibly, but the script would need to be granted access to the local file system by the user via something like a signed ActiveX Object or something like an HTA. I don't know the exact details around this as I've never done it (Down that path, there be dragons!)

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