Skip to content

Commit

Permalink
fix(app-file-manager): attach original file key when editing images
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel910 committed Dec 12, 2023
1 parent a8908e8 commit 9a9946b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
15 changes: 14 additions & 1 deletion packages/app-file-manager-s3/src/SimpleUploadStrategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,27 @@ import { UploadedFile, UploadOptions } from "@webiny/app/types";
import { GET_PRE_SIGNED_POST_PAYLOAD } from "./graphql";
import { FileUploadStrategy } from "~/index";

declare global {
interface File {
key?: string;
keyPrefix?: string;
}
}

export class SimpleUploadStrategy implements FileUploadStrategy {
async upload(file: File, { apolloClient, onProgress }: UploadOptions): Promise<UploadedFile> {
// 1. GET PreSignedPostPayload
const response = await apolloClient.query({
query: GET_PRE_SIGNED_POST_PAYLOAD,
fetchPolicy: "no-cache",
variables: {
data: { size: file.size, name: file.name, type: file.type }
data: {
size: file.size,
name: file.name,
type: file.type,
key: file.key,
keyPrefix: file.keyPrefix
}
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ export const EditAction: React.FC<EditActionProps> = props => {
onAccept={src => {
const blob = dataURLtoBlob(src);
blob.name = file.name;
blob.key = file.key.split("/").pop();
uploadFile(blob);
dispatch({ type: "hideImageEditor" });
}}
Expand Down

0 comments on commit 9a9946b

Please sign in to comment.