How to get uploaded picture information via JS (temporary save path, name, size) and then pass Ajax to the backend?

Source: Internet
Author: User
Tags readfile jquery file upload

Today in the forum to see such a problem, it is necessary to edit the collection.

Problem Description: How to get uploaded picture information via JS (temporary save path, name, size) and then pass to the backend via Ajax

The main topic is received by jquery

<name= "C_pic"  ID= "C_pic"  type= "File"  Class= "file">

The method used is:

var input = document.getElementById ("C_pic"); Input.addeventlistener (' Change ', ReadFile,false ); function  varthis. files[0];}

The main topic wants to use the Ajax Post method to upload the relevant information of the image to the backend,
The received file is an object file,
How do I convert to a data format that can be delivered using post?

When I saw the subject, I thought it was not easy, just pass the file through Json.stringify (Note: stringify () is used to parse the string from an object), the code is as follows:

var input = document.getElementById ("C_pic"); Input.addeventlistener (' Change ', ReadFile,false ); function  varthis. Files[0]; var file_json =// print out is: {}$.post (', File_json);}

The found print is an empty object: {}; have the trouble to tell, thank you!

So change a way of thinking with uploadfile plug-in or Baidu's Webuploader, which jquery file Upload is a jquery image upload component, support multi-file upload, cancel, delete, pre-upload thumbnail preview, list display image size, Support Upload progress bar display, support the server side of various dynamic language development.
If HTML5 is supported, it can be FormData implemented using AJAX uploads as well.

How to get uploaded picture information via JS (temporary save path, name, size) and then pass Ajax to the backend?

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.