Repository navigation
Closed
Description
Describe the Bug
Hi,
We cannot update the Media content (alt, resize image). We are using Azure Storage cloud for storing the media. We have implemented a select file for folder selection and uploaded the media to the selected folder. The first upload is working fine, but when we try to update the media, we get "Something went wrong" on the UI and "There was a problem while uploading the file. fetch failed" in the console.
Here are the hooks that we are using to manage the media folder:
hooks: {
beforeOperation: [
({ req, context, operation }) => {
if (['update'].includes(operation) && req?.file) {
context.newFileName = true;
context.fileName = req?.file?.name;
}
},
],
beforeChange: [
async ({ data, req, operation, collection, originalDoc, context }) => {
const payload = await getPayload({ config });
if (!['create', 'update'].includes(operation)) return data;
const folderPath = data.folder
? await getFullFolderPath(data.folder, req, MediaFolders.slug)
: 'Project';
const fileName: string = originalDoc?.filename ?? data.filename;
const relativePath =folderPath + '/' + fileName;
//Extract the extension (e.g., "png")
const extension = path.extname(fileName).replace('.', '').toLowerCase();
data.extension = null;
if (extension) {
data.extension = extension; // Save fileType in the collection field
}
//check if media exist at same location
const existingFile = await payload.find({
collection: collection.slug,
where: {
filename: { equals: relativePath },
},
limit: 1,
});
//if there throw error
if (existingFile.docs.length > 0 && operation === 'create') {
// throw new Error('File with this name already exists')
throw new APIError(`File with ${fileName} name already exists`, 400, [
{
message: `File with name ${fileName} already exists`,
},
]);
}
if (operation === 'update') {
const fileSize = originalDoc?.filesize ?? data?.filesize;
data.url = fileName;
data.thumbnailURL = fileName;
if (context?.newFileName) {
data.filename = `${folderPath}/${context.fileName}`;
data.filesize = fileSize;
} else {
data.filename = fileName;
data.filesize = fileSize;
}
} else {
data.filename = relativePath;
data.url = relativePath;
data.thumbnailURL = relativePath;
}
return data;
},
],
},
And the strange thing is, this setup is working fine on local, but failing on production. Even when I'm trying to upload new media with the URL, it's failing.
Link to the code that reproduces this issue
pnpx create-payload-app@latest -t blank
Reproduction Steps
- Create a Payload Application.
- Link Azure Storage for media upload.
- Implemented a collection for the media folder and linked it to the media collection for selection.
- Upload a media, it will work fine.
- Try to edit the media by updating alt and publish; this will fail.
Which area(s) are affected? (Select all that apply)
area: core
Environment Info
Binaries:
Node: 20.18.2
npm: N/A
Yarn: N/A
pnpm: N/A
Relevant Packages:
payload: 3.33.0
next: 15.2.2
@payloadcms/db-postgres: 3.33.0
@payloadcms/email-nodemailer: 3.33.0
@payloadcms/graphql: 3.33.0
@payloadcms/next/utilities: 3.33.0
@payloadcms/payload-cloud: 3.33.0
@payloadcms/plugin-cloud-storage: 3.33.0
@payloadcms/richtext-lexical: 3.33.0
@payloadcms/storage-azure: 3.33.0
@payloadcms/storage-s3: 3.33.0
@payloadcms/translations: 3.33.0
@payloadcms/ui/shared: 3.33.0
react: 19.0.0
react-dom: 19.0.0
Operating System:
Platform: win32
Arch: x64
Version: Windows 11 Pro
Available memory (MB): 16159
Available CPU cores: 8
Metadata
Metadata
Assignees
Labels
No labels
Activity
github-actions commentedon Jun 25, 2025
Please add a reproduction in order for us to be able to investigate.
Depending on the quality of reproduction steps, this issue may be closed if no reproduction is provided.
Why was this issue marked with the
invalid-reproductionlabel?To be able to investigate, we need access to a reproduction to identify what triggered the issue. We prefer a link to a public GitHub repository created with
create-payload-app@latest -t blankor a forked/branched version of this repository with tests added (more info in the reproduction-guide).To make sure the issue is resolved as quickly as possible, please make sure that the reproduction is as minimal as possible. This means that you should remove unnecessary code, files, and dependencies that do not contribute to the issue. Ensure your reproduction does not depend on secrets, 3rd party registries, private dependencies, or any other data that cannot be made public. Avoid a reproduction including a whole monorepo (unless relevant to the issue). The easier it is to reproduce the issue, the quicker we can help.
Please test your reproduction against the latest version of Payload to make sure your issue has not already been fixed.
I added a link, why was it still marked?
Ensure the link is pointing to a codebase that is accessible (e.g. not a private repository). "example.com", "n/a", "will add later", etc. are not acceptable links -- we need to see a public codebase. See the above section for accepted links.
Useful Resources
lukebennett commentedon Jun 25, 2025
It's probably #12876
rjay-hb commentedon Jun 25, 2025
@lukebennett But I'm using old version v3.33.0
lukebennett commentedon Jun 25, 2025
Good shout, missed that. There's been a couple of issues about the latest bug and I though this was another. Ignore me then, sorry - as you were!
fix: get external resource blocked (#12927)
github-actions commentedon Jul 4, 2025
This issue has been automatically locked.
Please open a new issue if this issue persists with any additional detail.