-
-
Notifications
You must be signed in to change notification settings - Fork 128
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
Upload a PDF file #83
Comments
Haven't personally tried this but have you attempted to set the headers to be |
Hello @lukecurtis93 Actually I haven't because I don't know-how. Can you help me with this, please? This is the import { Model as BaseModel } from 'vue-api-query';
export default class Model extends BaseModel {
// define a base url for a REST API
baseURL() {
return '/api';
}
// implement a default request method
request(config) {
return this.$http.request(config);
}
parameterNames() {
return Object.assign(super.parameterNames(), {
page: 'page[number]',
limit: 'page[size]'
});
}
} And the import Model from './Model';
export default class JobApplication extends Model {
resource() {
return 'v2/job_applications';
}
} |
+1 if someone can provide a I got around that using FormData objects directly. let post = new Post(this.post);
let uploadUrl = post.endpoint() + "/" + new PostDocument().resource(); |
Did not know there was a method |
Yes, I saw
|
@Tes3awy Have the tips provided helped you to find a solution? Is there still a need for a pure |
@Peter-Krebs I didn't get to find a solution that uses |
I don't have a solution for you except the approach mentioned above, sorry. There was no activity for over 3 weeks so I assumed the demand was dead. |
I am considering file uploads are out of scope, at this moment. Right now you
must handle it with another approach.
PR are welcome!
Em sex, 8 de nov de 2019 às 09:26, Peter Krebs <notifications@github.com>
escreveu:
Reopened #83 <#83>.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#83?email_source=notifications&email_token=AAA5BKZNLDT5PZVQ747ZIHLQSVLFZA5CNFSM4ISOBWFKYY3PNVWWK3TUL52HS4DFWZEXG43VMVCXMZLOORHG65DJMZUWGYLUNFXW5KTDN5WW2ZLOORPWSZGOUXOQSNQ#event-2782726454>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAA5BKY6WHRLGZOSMDS7UB3QSVLFZANCNFSM4ISOBWFA>
.
--
—
Robson Tenório
|
Hi, I have a small solution to this issue using // src/models/Model.js
import { Model as BaseModel } from "vue-api-query";
import objectToFormData from "object-to-formdata";
import { _ } from "vue-underscore";
export default class Model extends BaseModel {
baseURL() {
return "";
}
async request(config) {
if (config.method == "PUT") {
config.method = "POST";
config.data._method = "PUT";
}
const hasUpload = !_.chain(_.values(config.data))
.filter((value) => {
return value instanceof File;
})
.isEmpty()
.value();
if (hasUpload) {
config.data = objectToFormData(config.data, { indices: true });
}
return await this.$http.request(config);
}
} |
Add support to upload files by checking if data has instance of `File`. If so, it set the `Content-Type` to `multipart/form-data` and convert the data object to `FormData` using `object-to-formdata`. Based on comment by @alvaro-canepa at #83
🎉 This issue has been resolved in version 1.8.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
@alvaro-canepa Now you can simplify your model :) // src/models/Model.js
import { Model as BaseModel } from "vue-api-query";
import objectToFormData from "object-to-formdata";
import { _ } from "vue-underscore";
export default class Model extends BaseModel {
baseURL() {
return "";
}
async request(config) {
if (config.method == "PUT") {
config.method = "POST";
config.data._method = "PUT";
}
return await this.$http.request(config);
}
formData() {
return { indices: true };
}
} |
This what works for me better : /* eslint-disable no-underscore-dangle */
/* eslint-disable no-param-reassign */
/* eslint-disable class-methods-use-this */
import { Model as BaseModel } from 'vue-api-query'
import env from '@env'
export default class Model extends BaseModel {
// Define a base url for a REST API
baseURL() {
return `${env.baseURL}/api/admin`
}
// Implement a default request method
request(config) {
const isFormData = config.data instanceof FormData
if (isFormData && config.method === 'PUT') {
config.method = 'POST'
config.data.append('_method', 'PUT')
}
return this.$http.request(config)
}
} |
Hello there,
I am trying to use this awesome plugin to upload a PDF file. I have created a model for this:
Then, I call the model within the
.vue
file like that:The problem is that the POST request fails every time I try to submit the form because of the resume field. What am I doing wrong in here? Do I have to do any extra steps? Thank you
The text was updated successfully, but these errors were encountered: