Skip to content
This repository has been archived by the owner on Apr 4, 2022. It is now read-only.

Commit

Permalink
WIP - **dirty** code that works
Browse files Browse the repository at this point in the history
  • Loading branch information
leplatrem committed Jul 14, 2016
1 parent 62dd05f commit 2a02003
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"esdoc-es7-plugin": "0.0.3",
"esdoc-importpath-plugin": "0.0.1",
"eslint": "2.2.0",
"form-data": "^1.0.0-rc4",
"jsdom": "^9.4.1",
"kinto-node-test-server": "0.0.1",
"mocha": "^2.3.4",
Expand Down
14 changes: 7 additions & 7 deletions src/utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import atob from "atob";

import FormData from "form-data";

/**
* Chunks an array into n pieces.
Expand Down Expand Up @@ -266,8 +266,8 @@ export function extractFileInfo(dataURL) {
for(let i = 0; i < binary.length; i++) {
array.push(binary.charCodeAt(i));
}
const blob = new Blob([new Uint8Array(array)], {type});
return {name, blob};
// const blob = new Blob([new Uint8Array(array)], {type});
return {name, type, blob: Buffer.from(new Uint8Array(array))};
}

/**
Expand All @@ -278,11 +278,11 @@ export function extractFileInfo(dataURL) {
* @return {FormData}
*/
export function createFormData(dataURL, body) {
const {blob, name} = extractFileInfo(dataURL);
const {blob, type, name} = extractFileInfo(dataURL);
const formData = new FormData();
formData.append("attachment", blob, name);
for (const property in body) {
formData.append(property, JSON.stringify(body[property]));
}
// for (const property in body) {
// formData.append(property, JSON.stringify(body[property]));
// }
return formData;
}
7 changes: 3 additions & 4 deletions test/integration_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -982,7 +982,8 @@ describe("Integration tests", function() {
});

describe.only(".addAttachment()", () => {
const dataURL = "data:text/plain;name=test.txt;base64," + btoa("test");
const input = "test";
const dataURL = "data:text/plain;name=test.txt;base64," + btoa(input);

it("should create a record with an attachment", () => {
return coll
Expand All @@ -991,9 +992,7 @@ describe("Integration tests", function() {
console.log(server.logs.toString());
throw err;
})
.should.eventually.have.property("data")
.to.have.property("attachment")
.to.not.be.null;
.should.eventually.have.property("size").eql(input.length);
});
});

Expand Down

0 comments on commit 2a02003

Please sign in to comment.