-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
base: develop
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: 291b981 The changes in this PR will be included in the next version bump. This PR includes changesets to release 69 packages
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 |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
7 Skipped Deployments
|
@@ -400,7 +400,7 @@ export const useImportProducts = ( | |||
> | |||
) => { | |||
return useMutation({ | |||
mutationFn: (payload) => sdk.admin.product.import(payload), | |||
mutationFn: (payload) => sdk.admin.product.createImport(payload), |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Btw, I have been following this guide https://docs.medusajs.com/learn/fundamentals/workflows/long-running-workflow
There was a problem hiding this comment.
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.
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 |
There was a problem hiding this comment.
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 implementPUT
endpoints. - In case of s3, we cannot send additional headers like
Cookies
orAuthorization
, otherwise it will result in CORS error. Whereas, with Medusa, we have to send Auth headers.
No description provided.