Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,19 @@ In your project's root folder run:
To avoid using `Npm.depends` this package does not include any NPM module, so you will have to install them yourself by running the following command:

```
meteor npm install async-busboy@^0.6.2 brackets2dots@^1.1.0 lodash@^4.0.0 object-path@^0.11.4 randomstring@^1.1.5 react-dropzone@^3.12.2 recursive-iterator@^3.3.0 knox@^0.9.2 gm@^1.23.1
meteor npm install gm@^1.23.1 lodash@^4.0.0 randomstring@^1.1.5 react-dropzone@^3.12.2 recursive-iterator@^3.3.0 apollo-upload-client@^11.0.0
```

Alternatively, here you have a list of the packages and versions required, so you can add them to your project's `package.json`:

```json
{
"async-busboy": "^0.6.2",
"brackets2dots": "^1.1.0",
"gm": "^1.23.1",
"knox": "^0.9.2",
"lodash": "^4.0.0",
"object-path": "^0.11.4",
"randomstring": "^1.1.5",
"react-dropzone": "^3.12.2",
"recursive-iterator": "^3.3.0"
"recursive-iterator": "^3.3.0",
"apollo-upload-client": "^11.0.0"
}
```

Expand Down
105 changes: 53 additions & 52 deletions lib/client/interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,58 +68,59 @@ function serializeFormData(obj, formDataObj = {}, namespace) {
return formDataObj;
}

export const fileUploadMiddleware = {
applyMiddleware({ request, options }, next) {
if (isUpload(request)) {
const body = new FormData();
const data = [];
const printed = printRequest(request);
data.push({
operationName: printed.operationName || undefined,
debugName: printed.debugName || undefined,
query: printed.query,
variables: request.variables || {}
});
const serialised = serializeFormData({ data });
Object.entries(serialised).forEach(([name, value]) => {
if (typeof value !== typeof undefined) {
body.set(name, value);
}
});
options.headers = options.headers || new Headers();
options.headers.Accept = '*/*';
options.headers['Content-Type'] = undefined;
options.body = body;
}
next();
},
applyBatchMiddleware({ requests, options }, next) {
if (isUpload(requests)) {
const body = new FormData();
const data = [];
requests.forEach((request, i) => {
const printed = printRequest(request);
data.push({
operationName: printed.operationName || undefined,
debugName: printed.debugName || undefined,
query: printed.query,
variables: request.variables || {}
});
});
const serialised = serializeFormData({ data });
Object.entries(serialised).forEach(([name, value]) => {
if (typeof value !== typeof undefined) {
body.set(name, value);
}
});
options.headers = options.headers || new Headers();
options.headers.Accept = '*/*';
options.headers['Content-Type'] = undefined;
options.body = body;
}
next();
}
};
// DEPRECATED with apollo 2
//export const fileUploadMiddleware = {
// applyMiddleware({ request, options }, next) {
// if (isUpload(request)) {
// const body = new FormData();
// const data = [];
// const printed = printRequest(request);
// data.push({
// operationName: printed.operationName || undefined,
// debugName: printed.debugName || undefined,
// query: printed.query,
// variables: request.variables || {}
// });
// const serialised = serializeFormData({ data });
// Object.entries(serialised).forEach(([name, value]) => {
// if (typeof value !== typeof undefined) {
// body.set(name, value);
// }
// });
// options.headers = options.headers || new Headers();
// options.headers.Accept = '*/*';
// options.headers['Content-Type'] = undefined;
// options.body = body;
// }
// next();
// },
// applyBatchMiddleware({ requests, options }, next) {
// if (isUpload(requests)) {
// const body = new FormData();
// const data = [];
// requests.forEach((request, i) => {
// const printed = printRequest(request);
// data.push({
// operationName: printed.operationName || undefined,
// debugName: printed.debugName || undefined,
// query: printed.query,
// variables: request.variables || {}
// });
// });
// const serialised = serializeFormData({ data });
// Object.entries(serialised).forEach(([name, value]) => {
// if (typeof value !== typeof undefined) {
// body.set(name, value);
// }
// });
// options.headers = options.headers || new Headers();
// options.headers.Accept = '*/*';
// options.headers['Content-Type'] = undefined;
// options.body = body;
// }
// next();
// }
//};

export function createUploadNetworkInterface(opts) {
const batchedInterface = createBatchingNetworkInterface(opts);
Expand Down
12 changes: 5 additions & 7 deletions lib/client/main.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { withRenderContext } from 'meteor/vulcan:lib';
import { fileUploadMiddleware } from './interface';
import { registerTerminatingLink } from 'meteor/vulcan:lib';
import { createUploadLink } from 'apollo-upload-client';

registerTerminatingLink(createUploadLink())


export * from '../modules';
export { default as generateFieldSchema } from '../modules/generateFieldSchemaBase';
export { default as createFSCollection } from './createFSCollectionStub';

Meteor.startup(() => {
withRenderContext(renderContext => {
renderContext.apolloClient.networkInterface.use([fileUploadMiddleware]);
});
});
241 changes: 0 additions & 241 deletions lib/modules/components/Upload.jsx

This file was deleted.

Loading