Giter Club home page Giter Club logo

Comments (11)

tomasr78 avatar tomasr78 commented on June 29, 2024 2

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.

Irto avatar Irto commented on June 29, 2024

I have been through the same issue at the same endpoint. 😞 Someone knows any workaround?

from convertapi-node.

laurynas-convertapi avatar laurynas-convertapi commented on June 29, 2024

Hi @e10jon, @Irto I'd like to understand better what changed:

  1. Have you been using same version of the library before with the same size files successfully?
  2. Did you upgrade axios and the failures started after upgrade?
  3. 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.

Irto avatar Irto commented on June 29, 2024

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.

e10jon avatar e10jon commented on June 29, 2024

from convertapi-node.

tomasr78 avatar tomasr78 commented on June 29, 2024

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.

e10jon avatar e10jon commented on June 29, 2024

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.

tomasr78 avatar tomasr78 commented on June 29, 2024

@e10jon could you confirm that your files convert fine on the live demo page? https://www.convertapi.com/pdf-to-jpg

from convertapi-node.

e10jon avatar e10jon commented on June 29, 2024

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.

laurynas-convertapi avatar laurynas-convertapi commented on June 29, 2024

Thanks for the input! Keep alive might help in this situation. Adding an option to the client (enabled by default):
#69

from convertapi-node.

laurynas-convertapi avatar laurynas-convertapi commented on June 29, 2024

Enabled keep-alive in new v1.13.0 version.

from convertapi-node.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.