Comments (11)
It appears that you are utilizing JSON to post a file to the API, but this method may not be the best approach. Instead, it is recommended to use either multipart/form-data
or application/octet-stream
as the content type for posting the file, rather than application/json
.
Using application/json
has its drawbacks, including:
- The need to encode the file to Base64, which increases the payload by 30%
- Limitations on the size of JSON files that can be posted, which can prevent uploading larger files.
from convertapi-node.
I have been through the same issue at the same endpoint. π Someone knows any workaround?
from convertapi-node.
Hi @e10jon, @Irto I'd like to understand better what changed:
- Have you been using same version of the library before with the same size files successfully?
- Did you upgrade axios and the failures started after upgrade?
- Does it fail only with big files? Maybe you noticed approximately from which size the failures start?
Better understanding of the causes will help us with the appropriate fix.
from convertapi-node.
Hey @laurynas-baltsoft !
Have you been using same version of the library before with the same size files successfully?
I'm using convertapi
@ 1.12.0
.
Did you upgrade axios and the failures started after upgrade?
I'm a new user, I've integrated the convertapi at the end of last week. Never did a upgrade.
Does it fail only with big files? Maybe you noticed approximately from which size the failures start?
TBH I'm not sure it's related to the size of file. I've got some issue on files with less than 100KB. I've workaround this issue by adding a retry on may async job. So, I guess is probably some intermittent issue on your server side because next try it works.
from convertapi-node.
from convertapi-node.
Hello everyone, would you kindly share your integration codes? Also, I am curious to know if you use Async in your process.
from convertapi-node.
Sure. My integration is very simply. It looks like this:
const convertApi = new ConvertApi('XXX')
const convertRes = await convertApi.convert('jpg', { File: 'path/to/file.docx' })
from convertapi-node.
@e10jon could you confirm that your files convert fine on the live demo page? https://www.convertapi.com/pdf-to-jpg
from convertapi-node.
I went ahead and created my own simple client library. It works every time I make an API call now. Feel free to reuse as you please!
import { basename, extname } from 'node:path'
import { readFile, writeFile } from 'fs/promises'
export class ConvertApi {
constructor(private secret: string) {}
async convert(format: 'png' | 'jpg', pathToFile: string) {
const file = await readFile(pathToFile)
const base64File = file.toString('base64')
const filename = basename(pathToFile)
const extension = extname(pathToFile).replace(/\./, '')
const req = await fetch(`https://v2.convertapi.com/convert/${extension}/to/${format}?Secret=${this.secret}`, {
method: 'POST',
body: JSON.stringify({
Parameters: [
{
Name: 'File',
FileValue: {
Name: filename,
Data: base64File,
},
},
{
Name: 'StoreFile',
Value: false,
},
],
}),
headers: {
'Content-Type': 'application/json',
},
})
const res = (await req.json()) as { Files: { FileName: string; FileExt: string; FileSize: number; FileData: string }[] }
return {
files: res.Files.map((data) => ({
fileName: data.FileName,
save: async (path: string) => {
await writeFile(path, Buffer.from(data.FileData, 'base64'))
},
})),
}
}
}
from convertapi-node.
Thanks for the input! Keep alive might help in this situation. Adding an option to the client (enabled by default):
#69
from convertapi-node.
Enabled keep-alive in new v1.13.0 version.
from convertapi-node.
Related Issues (20)
- Update typings after version 1.18.0 HOT 5
- Review PR for typings in DefinitelyTyped HOT 3
- TypeError: convertapi_1.default is not a function HOT 2
- Request body larger than maxBodyLength Limit HOT 4
- require(...) is not a function HOT 2
- StoreFile is set to true, should be false & normalizeParams should be updated HOT 7
- Convert docx file received in formData will respond to 415 error. HOT 1
- Why I got TypeError: _fs2.default.createReadStream is not a function HOT 1
- Do not pass any TimeOut property to ConvertAPI and set HTTP Client timeout to 1800 seconds HOT 3
- Server URL overwrite bug HOT 1
- compare API is returning - Code: 5009, Message: 'File id is not valid.' HOT 1
- Async Workflow broken HOT 1
- Alternative "Converter" parameter lowercase
- File parameters not interpreted as files HOT 3
- ConvertApiUser.SecondsLeft property is depreciated HOT 1
- Error: socket hang up HOT 1
- Update axios version to 1.6.0 HOT 2
- Is there a way to pass a file buffer or stream instead of a path? HOT 1
- Default param issue HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from convertapi-node.