文件上传扼流圈有时会继续100次

时间:2017-08-18 07:18:00

标签: python linux curl flask flask-restful

我使用cURL调用我的Web服务将图像上传到服务器。它有时会起作用,而在其他时候,它只是在这一点上讨厌如下所示。行为是非常不一致的 - 有时我设法上传图像并获得响应,而在其他时候它会像下面所示那样坐在那里。我错过了什么/做错了什么?

代码段:

filename = str(id) + '.' + str(int(time.time())) + '.' +  secure_filename(file.filename)
filename_absolute = os.path.join(app.config['UPLOAD_FOLDER'], picture_type, filename)
file.save(filename_absolute)

示例通话[SUCCESS]:

curl -v -F "id=1" -F 'file=@/tmp/2.png' -F 'picture_type=user' http://HOST:5000/api/v1/upload-picture
*   Trying 45.76.12.43...
* Connected to HOST (HOST) port 5000 (#0)
> POST /api/v1/upload-picture HTTP/1.1
> Host: HOST:5000
> User-Agent: curl/7.47.0
> Accept: */*
> Content-Length: 154309
> Expect: 100-continue
> Content-Type: multipart/form-data; boundary=------------------------7cc65a2371111afb
> 
< HTTP/1.1 100 Continue
* HTTP 1.0, assume close after body
< HTTP/1.0 200 OK
< Content-Type: application/json
< Content-Length: 136
< Server: Werkzeug/0.9.4 Python/2.7.6
< Date: Fri, 18 Aug 2017 07:16:00 GMT
< 
{
  "data": {
    "link": "HOST:5000/api/v1/user/view-picture/1"
  }, 
  "error": 0, 
  "message": "File uploaded successfully"
* Closing connection 0
}

示例通话[FAIL]:

curl -v -F "id=1" -F 'file=@/tmp/2.png' -F 'picture_type=user' http://HOST:5000/api/v1/uplad-picture
*   Trying HOST...
* Connected to HOST (HOST) port 5000 (#0)
> POST /api/v1/uplad-picture HTTP/1.1
> Host: HOST:5000
> User-Agent: curl/7.47.0
> Accept: */*
> Content-Length: 154309
> Expect: 100-continue
> Content-Type: multipart/form-data; boundary=------------------------046a40f6e0480526
> 
* Done waiting for 100-continue

0 个答案:

没有答案