首页 > 解决方案 > 服务器请求中断 Heroku

问题描述

我正在使用 React Native 和 Django。一切正常,直到我提出请求并收到以下错误:

sock=backend at=error code=H18 desc="Server Request Interrupted" method=POST path="/api/obtain-img" host=notarealapp.herokuapp.com request_id=... fwd="..." dyno=web.1 connect=0ms service=22ms status=503 bytes=316 protocol=https

另外,我不知道这是否有用的信息,但我也收到以下错误:

<rest_framework.request.Request: POST '/api/obtain-img'>

我使用的获取代码是这样的:

let token = await SecureStore.getItemAsync("token");
console.log(uri);
let filename = uri.split("/").pop();

let match = /\.(\w+)$/.exec(filename);
let type = match ? `image/${match[1]}` : `image`;

let formData = new FormData();
formData.append("image", { uri: uri, name: filename, type: type });
// formData.append("cateogry", category);
// formData.append("mission", value);
console.log(formData);
return await fetch("https://notarealapp.herokuapp.com/api/obtain-img", {
  method: "POST",
  headers: {
    "content-type": "multipart/form-data",
    Authorization: `JWT ${JSON.parse(token)}`,
  },
  body: formData,
})
  .then((res) => res.json())
  .then((json) => console.log(json))
  .catch((error) => console.error(error));

我的 Django 代码如下:

class ObtainImageUri(APIView):
    permission_classes = [IsAuthenticated]

    def post(self, request, format=None):
        print(request)
        return Response({"succes": "The receipt was stored successfully."}, status=200)

我愿意接受任何帮助。

谢谢

标签: javascriptdjangoreact-nativeheroku

解决方案


推荐阅读