Giter Site home page Giter Site logo

upic配置不成功 about easyimages2.0 HOT 1 CLOSED

icret avatar icret commented on July 17, 2024
upic配置不成功

from easyimages2.0.

Comments (1)

JJPro avatar JJPro commented on July 17, 2024

@hyhy01 @icret Holy shit, I got it working in uPic.

image

You have to specify Content-Type as multipart/form-data in request header. Otherwise, it will send the data, including the file, as pure JSON.


The following is my debug journey and postmortem:

First, I checked nginx log to make sure that the server is getting the request. And that's a check.
Then I want to see what the server returns to uPic like so:
I tried to search for uPic logs, but I couldn't find its log file, nor any marks in system logs.
So I decided to capture the network traffic with tcpdump, then use Wireshark to analyze the traffic.
There, I can see that easyimage server sends the following message back to uPic:

{
    "result": "failed",
    "code": 204,
    "message": "没有选择上传的文件"
}

Hmmm, interesting.

Then I analyzed traffic from curl and Postman as well for comparison.
There I can see that, both curl and Postman is sending the request as type multipart/form-data, while uPic is doing that via application/json, which is a sub-type of html/text.
Aha! I was like, WHAT?! uPic, how dare you send a file via json.

这件事对于开发人员的经验/教训:

  1. When sending a file, never forget to attach header Content-type: multipart/form-data to the request. For form submission, browser will auto specify the correct Content-type, but in REST/Ajax calls, we developers have to manually specify the correct Content-type for use.
  2. @icret At this moment, easyimage is returning HTTP status code 200 (OK) in the above situation, I believe it is more appropriate to return 400 (Bad Request) instead. With that, apps like uPic will be able to properly detect and handle the error, and probably show an error popup to inform its user.

from easyimages2.0.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.