Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(be): implement image upload #1514

Merged
merged 33 commits into from
May 29, 2024
Merged

Conversation

Jaehyeon1020
Copy link
Member

@Jaehyeon1020 Jaehyeon1020 commented Feb 27, 2024

Description

Closes #1495

이미지 업로드 기능을 구현합니다.
Problem description에 이미지를 삽입하는 용도로 사용이 가능합니다.

Additional context

  • 이미지의 최대 크기는 5MB입니다.
  • src 속성에 업로드된 이미지의 url이 담겨 반환됩니다. img 태그의 src 속성에 넣어 이미지 삽입 기능의 구현이 가능합니다.

참고 스크린샷
스크린샷 2024-02-28 오후 10 01 17


Before submitting the PR, please make sure you do the following

@Jaehyeon1020 Jaehyeon1020 self-assigned this Feb 27, 2024
Copy link

vercel bot commented Feb 27, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
codedang ✅ Ready (Inspect) Visit Preview May 29, 2024 1:23am

@cho-to
Copy link
Contributor

cho-to commented Feb 29, 2024

균서님이랑 저랑 branch 전환해서 이미지 파일 바꿔서 시도했는데 아래 에러가 공통적으로 떠서.. 혹시 확인가능하실까요?

{
  "errors": [
    {
      "message": "Cannot return null for non-nullable field Image.src.",
      "locations": [
        {
          "line": 1,
          "column": 64
        }
      ],
      "path": [
        "uploadImage",
        "src"
      ],
      "extensions": {
        "code": "INTERNAL_SERVER_ERROR",
        "stacktrace": [
          "Error: Cannot return null for non-nullable field Image.src.",
          "    at completeValue (/workspace/node_modules/.pnpm/graphql@16.8.1/node_modules/graphql/execution/execute.js:605:13)",
          "    at executeField (/workspace/node_modules/.pnpm/graphql@16.8.1/node_modules/graphql/execution/execute.js:500:19)",
          "    at executeFields (/workspace/node_modules/.pnpm/graphql@16.8.1/node_modules/graphql/execution/execute.js:414:22)",
          "    at completeObjectValue (/workspace/node_modules/.pnpm/graphql@16.8.1/node_modules/graphql/execution/execute.js:925:10)",
          "    at completeValue (/workspace/node_modules/.pnpm/graphql@16.8.1/node_modules/graphql/execution/execute.js:646:12)",
          "    at completeValue (/workspace/node_modules/.pnpm/graphql@16.8.1/node_modules/graphql/execution/execute.js:595:23)",
          "    at /workspace/node_modules/.pnpm/graphql@16.8.1/node_modules/graphql/execution/execute.js:497:9",
          "    at processTicksAndRejections (node:internal/process/task_queues:95:5)",
          "    at execute (/workspace/node_modules/.pnpm/@apollo+server@4.10.0_graphql@16.8.1/node_modules/@apollo/server/src/requestPipeline.ts:547:31)",
          "    at processGraphQLRequest (/workspace/node_modules/.pnpm/@apollo+server@4.10.0_graphql@16.8.1/node_modules/@apollo/server/src/requestPipeline.ts:433:26)",
          "    at internalExecuteOperation (/workspace/node_modules/.pnpm/@apollo+server@4.10.0_graphql@16.8.1/node_modules/@apollo/server/src/ApolloServer.ts:1313:12)",
          "    at runHttpQuery (/workspace/node_modules/.pnpm/@apollo+server@4.10.0_graphql@16.8.1/node_modules/@apollo/server/src/runHttpQuery.ts:232:27)",
          "    at runPotentiallyBatchedHttpQuery (/workspace/node_modules/.pnpm/@apollo+server@4.10.0_graphql@16.8.1/node_modules/@apollo/server/src/httpBatching.ts:85:12)",
          "    at ApolloServer.executeHTTPGraphQLRequest (/workspace/node_modules/.pnpm/@apollo+server@4.10.0_graphql@16.8.1/node_modules/@apollo/server/src/ApolloServer.ts:1087:14)"
        ]
      }
    }
  ],
  "data": null
}

@Jaehyeon1020
Copy link
Member Author

균서님이랑 저랑 branch 전환해서 이미지 파일 바꿔서 시도했는데 아래 에러가 공통적으로 떠서.. 혹시 확인가능하실까요?

{
  "errors": [
    {
      "message": "Cannot return null for non-nullable field Image.src.",
      "locations": [
        {
          "line": 1,
          "column": 64
        }
      ],
      "path": [
        "uploadImage",
        "src"
      ],
      "extensions": {
        "code": "INTERNAL_SERVER_ERROR",
        "stacktrace": [
          "Error: Cannot return null for non-nullable field Image.src.",
          "    at completeValue (/workspace/node_modules/.pnpm/graphql@16.8.1/node_modules/graphql/execution/execute.js:605:13)",
          "    at executeField (/workspace/node_modules/.pnpm/graphql@16.8.1/node_modules/graphql/execution/execute.js:500:19)",
          "    at executeFields (/workspace/node_modules/.pnpm/graphql@16.8.1/node_modules/graphql/execution/execute.js:414:22)",
          "    at completeObjectValue (/workspace/node_modules/.pnpm/graphql@16.8.1/node_modules/graphql/execution/execute.js:925:10)",
          "    at completeValue (/workspace/node_modules/.pnpm/graphql@16.8.1/node_modules/graphql/execution/execute.js:646:12)",
          "    at completeValue (/workspace/node_modules/.pnpm/graphql@16.8.1/node_modules/graphql/execution/execute.js:595:23)",
          "    at /workspace/node_modules/.pnpm/graphql@16.8.1/node_modules/graphql/execution/execute.js:497:9",
          "    at processTicksAndRejections (node:internal/process/task_queues:95:5)",
          "    at execute (/workspace/node_modules/.pnpm/@apollo+server@4.10.0_graphql@16.8.1/node_modules/@apollo/server/src/requestPipeline.ts:547:31)",
          "    at processGraphQLRequest (/workspace/node_modules/.pnpm/@apollo+server@4.10.0_graphql@16.8.1/node_modules/@apollo/server/src/requestPipeline.ts:433:26)",
          "    at internalExecuteOperation (/workspace/node_modules/.pnpm/@apollo+server@4.10.0_graphql@16.8.1/node_modules/@apollo/server/src/ApolloServer.ts:1313:12)",
          "    at runHttpQuery (/workspace/node_modules/.pnpm/@apollo+server@4.10.0_graphql@16.8.1/node_modules/@apollo/server/src/runHttpQuery.ts:232:27)",
          "    at runPotentiallyBatchedHttpQuery (/workspace/node_modules/.pnpm/@apollo+server@4.10.0_graphql@16.8.1/node_modules/@apollo/server/src/httpBatching.ts:85:12)",
          "    at ApolloServer.executeHTTPGraphQLRequest (/workspace/node_modules/.pnpm/@apollo+server@4.10.0_graphql@16.8.1/node_modules/@apollo/server/src/ApolloServer.ts:1087:14)"
        ]
      }
    }
  ],
  "data": null
}

아마 일건님이 추가로 작업하신 내용과 관련해서 문제가 있을 것 같은데, 제가 아직 코드를 정리를 하지 못해서 확인 후 수정하고 나서 다시 알려드리겠습니다!

- 샘플 이미지 추가
- src, alt 반환하던 것에서 src만 반환하는 것으로 변경
Copy link
Contributor

github-actions bot commented Mar 1, 2024

Images automagically compressed by Calibre's image-actions

Compression reduced images by 25.2%, saving 19.63 KB.

Filename Before After Improvement Visual comparison
backend/apps/admin/src/problem/mock/sample.png 77.86 KB 58.24 KB -25.2% View diff

19 images did not require optimisation.

@Jaehyeon1020
Copy link
Member Author

@cho-to 오류 해결 되었습니다~

@Jaehyeon1020 Jaehyeon1020 requested review from gyunseo and k1g99 March 2, 2024 16:14
@Jaehyeon1020 Jaehyeon1020 merged commit 4680a36 into main May 29, 2024
10 checks passed
@Jaehyeon1020 Jaehyeon1020 deleted the 1495-implement-image-upload branch May 29, 2024 07:20
mnseok pushed a commit that referenced this pull request Jul 4, 2024
* feat(be): implement image upload to S3

* docs(be): add upload image api docs

* chore(be): modify image bucket baseurl

* docs(be): add assert

* chore(be): add alt property to return type of image-upload api

* chore(infra): rename testcase to storage

* feat(infra): add env for media bucket

* chore(be): add sample image and modify return object
- 샘플 이미지 추가
- src, alt 반환하던 것에서 src만 반환하는 것으로 변경

* Optimised images with calibre/image-actions

* chore(be): add s3-media-provider to test code

* chore(be): use relative path for sample image

* chore(be): replace client with media-client

* feat(be): add delete-image function

* refactor: combine bucket setup scripts

* fix(be): modify modify image size calculating logic
- 5MB 초과 파일이 들어왔을 때도 계속해서 파일 사이즈를 계산하는 문제 수정
- 5MB 초과 시 파일 사이즈 계산 중지, 예외 던지도록 구현

* chore(be): modify filename to use uuid only

* chore(be): remove duplicated import lines

* chore(be): remove file extension

* feat(be): add delete-image and improve image upload, delete logic

* docs(be): add delete-image api docs

* chore(be): parallelize deleting image logic

* chore(be): parallelize image-delete api

---------

Co-authored-by: k1g99 <idmatthew9546@gmail.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Jiyun Park <80032256+cho-to@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

이미지 업로드 기능 구현
4 participants