The correct method for obtaining the Upload File name through web. py, and web. py for obtaining the Upload File Name
Directly cut into the topic, upload files from the HTML page, and Python receives and processes the files. But I found some minor problems. Writing it out is a matter of accumulation!
HTML page code:
Copy codeThe Code is as follows:
<Form action = "/admin/addgoodsaction/" method = "post" enctype = "multipart/form-data">
<Input type = "file" name = "image"/>
</Form>
Python processing code:
Copy codeThe Code is as follows:
I = web. input ()
Return I. image. filename
The execution result switch prompt is as follows:
Copy codeThe Code is as follows:
<Type 'exceptions. attributeerror'> at/admin/addgoodsaction/
'Str' object has no attribute 'filename'
The system prompts that this object does not find the filename attribute. At first, I thought it was an error to receive the object, so I directly
Copy codeThe Code is as follows:
I = web. input ()
Return I. image
The uploaded image can be printed normally. It proves that there is no error in the receiving object. Why is the received object correct, but the system prompts that there is no filename attribute?
I changed the code:
Copy codeThe Code is as follows:
I = web. input (image = {})
Return I. image. filename
Upload a hello.jpg image and print hello.jpg. The problem is solved. From the code above, if the image object is not initialized, the filename attribute cannot be found. After initialization, the filename attribute can be obtained to obtain the uploaded file name.
How does JAVA obtain the uploaded file name?
I agree to the analysis on the upstairs. I also want to provide a suggestion. I can try to write the code step by step for ease of reading.
Define filename and filepath first, and then you want the image to appear in the specified area in subsequent operations.
You can directly use filename. The file name to be uploaded is its. getIPTimeStampRand () + "." + item. getName (). split ("\.") [1].
Get Upload File Name
Send the code -------- or you can find an asp upload component. All problems are solved.