Skip to content

feat: wire up direct uploads with local file provider #12643

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

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from

Conversation

thetutlage
Copy link
Contributor

No description provided.

@thetutlage thetutlage requested a review from a team as a code owner May 29, 2025 08:25
Copy link

changeset-bot bot commented May 29, 2025

🦋 Changeset detected

Latest commit: 291b981

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 69 packages
Name Type
@medusajs/file-local Patch
@medusajs/core-flows Patch
@medusajs/js-sdk Patch
@medusajs/dashboard Patch
integration-tests-http Patch
@medusajs/medusa Patch
@medusajs/admin-bundler Patch
@medusajs/test-utils Patch
@medusajs/medusa-oas-cli Patch
@medusajs/analytics Patch
@medusajs/api-key Patch
@medusajs/auth Patch
@medusajs/cart Patch
@medusajs/currency Patch
@medusajs/customer Patch
@medusajs/file Patch
@medusajs/fulfillment Patch
@medusajs/index Patch
@medusajs/inventory Patch
@medusajs/link-modules Patch
@medusajs/locking Patch
@medusajs/notification Patch
@medusajs/order Patch
@medusajs/payment Patch
@medusajs/pricing Patch
@medusajs/product Patch
@medusajs/promotion Patch
@medusajs/region Patch
@medusajs/sales-channel Patch
@medusajs/stock-location Patch
@medusajs/store Patch
@medusajs/tax Patch
@medusajs/user Patch
@medusajs/workflow-engine-inmemory Patch
@medusajs/workflow-engine-redis Patch
@medusajs/oas-github-ci Patch
@medusajs/cache-inmemory Patch
@medusajs/cache-redis Patch
@medusajs/event-bus-local Patch
@medusajs/event-bus-redis Patch
@medusajs/analytics-local Patch
@medusajs/analytics-posthog Patch
@medusajs/auth-emailpass Patch
@medusajs/auth-github Patch
@medusajs/auth-google Patch
@medusajs/file-s3 Patch
@medusajs/fulfillment-manual Patch
@medusajs/locking-postgres Patch
@medusajs/locking-redis Patch
@medusajs/notification-local Patch
@medusajs/notification-sendgrid Patch
@medusajs/payment-stripe Patch
@medusajs/framework Patch
@medusajs/modules-sdk Patch
@medusajs/orchestration Patch
@medusajs/types Patch
@medusajs/utils Patch
@medusajs/workflows-sdk Patch
@medusajs/cli Patch
@medusajs/telemetry Patch
@medusajs/admin-sdk Patch
@medusajs/admin-shared Patch
@medusajs/admin-vite-plugin Patch
@medusajs/icons Patch
@medusajs/toolbox Patch
@medusajs/ui-preset Patch
create-medusa-app Patch
medusa-dev-cli Patch
@medusajs/ui Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

vercel bot commented May 29, 2025

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

Name Status Preview Comments Updated (UTC)
medusa-dashboard ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 3, 2025 9:20am
7 Skipped Deployments
Name Status Preview Comments Updated (UTC)
api-reference ⬜️ Ignored (Inspect) Jun 3, 2025 9:20am
api-reference-v2 ⬜️ Ignored (Inspect) Visit Preview Jun 3, 2025 9:20am
docs-ui ⬜️ Ignored (Inspect) Visit Preview Jun 3, 2025 9:20am
docs-v2 ⬜️ Ignored (Inspect) Visit Preview Jun 3, 2025 9:20am
medusa-docs ⬜️ Ignored (Inspect) Visit Preview Jun 3, 2025 9:20am
resources-docs ⬜️ Ignored (Inspect) Visit Preview Jun 3, 2025 9:20am
user-guide ⬜️ Ignored (Inspect) Visit Preview Jun 3, 2025 9:20am

@@ -400,7 +400,7 @@ export const useImportProducts = (
>
) => {
return useMutation({
mutationFn: (payload) => sdk.admin.product.import(payload),
mutationFn: (payload) => sdk.admin.product.createImport(payload),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instructing frontend to use the new endpoint that uses direct file uploads

},
{ toCreate: 0, toUpdate: 0 }
)
contents.on("error", reject)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Handling stream errors and rejecting the promise

processImportChunksStepId,
{
name: processImportChunksStepId,
async: true,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I do not convert this step to async, then the imports confirm endpoint waits until this step is done (which takes minutes with larger uploads).

@carlos-r-l-rodrigues can you confirm if my assumption is correct?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When composing the workflow, as the step to wait for confirmation is async, this workflow will be automatically flagged as async.
so, here the async flag is just optional.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay. But I noticed that without this flag, the endpoint waits for the workflow to finish. Maybe what I need is background execution

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay. But I noticed that without this flag, the endpoint waits for the workflow to finish. Maybe what I need is background execution

This shouldn't happen. When there is one async step, the worklfow.run will return as soon as it get to this step. When that step is finished, it will continue in another process.

Comment on lines +133 to +149
const form = new FormData()
form.append("files", body.file)

const localUploadResponse = await this.client.fetch<{
files: HttpTypes.AdminUploadFile
}>("admin/uploads", {
method: "POST",
headers: {
...headers,
// Let the browser determine the content type.
"content-type": null,
},
body: form,
query,
})

response.filename = localUploadResponse.files[0].id
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we are using local file provider to uploading a file, we have to handle it specially in the frontend.

  • In case of s3, we have to send a PUT request. Whereas, with Medusa we do not implement PUT endpoints.
  • In case of s3, we cannot send additional headers like Cookies or Authorization, otherwise it will result in CORS error. Whereas, with Medusa, we have to send Auth headers.

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.

2 participants