Skip to content

Commit

Permalink
fix: get presignedPostData via GQL
Browse files Browse the repository at this point in the history
  • Loading branch information
adrians5j committed Oct 9, 2019
1 parent 3f93a76 commit bc11b2c
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions packages/app/src/plugins/fileUploaderPlugin.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
// @flow
import type { FileUploaderPlugin } from "@webiny/app/types";
import gql from "graphql-tag";
import get from "lodash.get";

const UPLOAD_FILE = gql`
mutation UploadFile($data: UploadFileInput!) {
files {
upload(data: $data) {
uploadFile(data: $data) {
data {
data
file {
src
type
name
size
key
}
}
error {
message
}
}
}
}
Expand All @@ -24,14 +29,18 @@ export default (): FileUploaderPlugin => ({
type: "file-uploader",
name: "file-uploader",
upload: async (file: File, { apolloClient }) => {
console.log("ideeee");
const presignedPostPayload = await apolloClient.mutate({
let presignedPostPayload = await apolloClient.mutate({
mutation: UPLOAD_FILE,
variables: {
data: { size: file.size, name: file.name, type: file.type }
}
});
console.log("dobeo presigned", presignedPostPayload);

presignedPostPayload = get(presignedPostPayload, "data.files.uploadFile");
if (presignedPostPayload.error) {
console.log(presignedPostPayload.error.message); // eslint-disable-line
return;
}

return await new Promise((resolve, reject) => {
const formData = new window.FormData();
Expand Down

0 comments on commit bc11b2c

Please sign in to comment.