Skip to content

Commit

Permalink
Merge pull request #257 from editor-js/fix-issue
Browse files Browse the repository at this point in the history
fix(issue 256): upload issue with images fix
  • Loading branch information
neSpecc committed Jul 17, 2024
2 parents 1d9f0e7 + 3180915 commit de05642
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
14 changes: 8 additions & 6 deletions dev/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,12 @@ class ServerExample {

this.getForm(request)
.then(({files}) => {
let image = files[this.fieldName] || {};
let image = files[this.fieldName][0] || {};

responseJson.success = 1;
responseJson.file = {
url: image.path,
name: image.name,
url: 'file://' + image.filepath,
name: image.newFilename,
size: image.size
};
})
Expand Down Expand Up @@ -147,10 +147,12 @@ class ServerExample {
*/
getForm(request) {
return new Promise((resolve, reject) => {
const form = new formidable.IncomingForm();
const form = new formidable.IncomingForm({
uploadDir: this.uploadDir,
keepExtensions: true
});

form.uploadDir = this.uploadDir;
form.keepExtensions = true;
console.error('the form info:', form);

form.parse(request, (err, fields, files) => {
if (err) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@editorjs/image",
"version": "2.9.1",
"version": "2.9.2",
"keywords": [
"codex editor",
"image",
Expand Down
2 changes: 1 addition & 1 deletion src/types/codexteam__ajax.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ declare module '@codexteam/ajax' {
url?: string;
data?: any;
accept?: string;
headers?: Headers;
headers?: object;
beforeSend?: (files: File[]) => void;
fieldName?: string;
type?: string;
Expand Down
10 changes: 5 additions & 5 deletions src/uploader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,12 @@ export default class Uploader {
upload = ajax.transport({
url: this.config.endpoints.byFile,
data: this.config.additionalRequestData,
accept: this.config.types,
headers: new Headers(this.config.additionalRequestHeaders as Record<string, string>),
accept: this.config.types || 'image/*',
headers: this.config.additionalRequestHeaders as Record<string, string>,
beforeSend: (files: File[]) => {
preparePreview(files[0]);
},
fieldName: this.config.field,
fieldName: this.config.field || 'image',
}).then((response: any) => response.body);
}

Expand Down Expand Up @@ -133,7 +133,7 @@ export default class Uploader {
url: url,
}, this.config.additionalRequestData),
type: ajax.contentType.JSON,
headers: new Headers(this.config.additionalRequestHeaders as Record<string, string>),
headers: this.config.additionalRequestHeaders as Record<string, string>,
}).then((response: any) => response.body);
}

Expand Down Expand Up @@ -193,7 +193,7 @@ export default class Uploader {
url: this.config.endpoints.byFile,
data: formData,
type: ajax.contentType.JSON,
headers: new Headers(this.config.additionalRequestHeaders as Record<string, string>),
headers: this.config.additionalRequestHeaders as Record<string, string>,
}).then((response: any) => response.body);
}

Expand Down

0 comments on commit de05642

Please sign in to comment.