Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(issue 256): upload issue with images fix #257

Merged
merged 4 commits into from
Jul 17, 2024
Merged
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
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
Loading