June222 / Smart-Factory-Project

0 stars 1 forks source link

Response Error: status code 308 #26

Closed June222 closed 8 months ago

June222 commented 8 months ago

firestore까지는 업로드가 되는데 모델 API로 전송이 되지 않음.

June222 commented 8 months ago

image

"Internal Server Error"

YeoJiSu commented 8 months ago

간단한 url이 들어왔을 때에만 처리가 가능했네요

수정 전

zip(*test_df['ImageId_ClassId'].str.split('_'))

수정 후

test_df['ImageId_ClassId'].str.rsplit('_', n=1)

추가로, 이미지 저장시 random string으로 저장되게하여 해결했습니다.

June222 commented 8 months ago

요약:

1. 서버측 url 파싱 방법의 문제로 전달받은 url이 제대로 처리되지 않음.

firestore의 이미지 url은 전달해도 상관없음

2. 분류된 이미지의 파일이름을 원본이미지의 url을 그대로 쓸 경우 컴퓨터가 파일이름임에도 url로 인식하는 문제가 생김

파일이름에 무작위 string을 섞어 url과 혼동방지

3. url의 마지막 부분에 '/' 이 빠짐

4. Flutter 에서 json 형태의 파일 전달

Map형태의 body를 전달할 경우 MIME은 "x-www-format"으로 고정 String 형태의 body를 전달할 경우 MIME은 'text/plain' 이 default

  1. JsonEncode(_url) 해줘야함 return type은 String
  2. header의 'Content-Type'을 'application/json' 으로 변경
  3. url의 모든 부분은 같아야함.
  4. 하나라도 빠지면 안됨!
var headers = {
      'Content-Type': 'application/json',
      'authorization': 'Basic c3R1ZHlkb3RlOnN0dWR5ZG90ZTEyMw=='
    };
    log("url parsing ${Res.succesMessage}");
    var response = await http.post(
      _apiURL,
      headers: headers,
      body: jsonEncode(SteelImageModel.toJson(steelImageModel)),
    );

참고: 공식 문서

Sends an HTTP POST request with the given headers and body to the given URL.

[body] sets the body of the request. It can be a [String], a [List] or a [Map<String, String>]. If it's a String, it's encoded using [encoding] and used as the body of the request. The content-type of the request will default to "text/plain".

If [body] is a List, it's used as a list of bytes for the body of the request.

If [body] is a Map, it's encoded as form fields using [encoding]. The content-type of the request will be set to "application/x-www-form-urlencoded"; this cannot be overridden.

[encoding] defaults to [utf8].

For more fine-grained control over the request, use [Request] or [StreamedRequest] instead.