• Empleos
  • Sobre nosotros
  • profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
  • empresas
    • Inicio
    • Publicar vacante
    • Nuestro proceso
    • Precios
    • Pruebas Online
    • Nómina
    • Blog
    • Comercial
    • Calculadora de salario

0

295
Vistas
Am Using tinify in node js. Wow can we download supressed file using nodejs?

I am using npm install --save tinify then uploading my image files using nodejs but I need compressed .zip file in my system .

When I'm uploading my image files through browser at https://tinypng.com after uploading it shows download option that is perfect. But how can we do same through nodejs?

Here is my code:

var tinify = require("tinify");
tinify.key = "myRightApiCode";
var fs = require("fs");

fs.readFile("C:/Users/sourav/images/pgL_NA-10005_5.jpg", function(err, 
sourceData) {
if (err) throw err;
tinify.fromBuffer(sourceData).toBuffer(function(err, resultData) {
if (err) throw err;
// ...
console.log(resultData);
//need compressed file in my system
});
}); 
almost 3 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

You can use tinify's method that converts and writes the compressed image at once:

var sourceFile = tinify.fromFile("uncompressed.jpg");
sourceFile.toFile("compressed.jpg");

Alternatively in your method try:

var tinify = require("tinify");
tinify.key = "myRightApiCode";
var fs = require("fs");

fs.readFile("C:/Users/sourav/images/pgL_NA-10005_5.jpg", function(err, 
sourceData) {
    if (err) throw err;
    tinify.fromBuffer(sourceData).toBuffer(function(err, resultData) {
        if (err) throw err;

        fs.writeFile('C:/Users/sourav/images/optimized.jpg', resultData, function (err) {
            if (err) throw err;
            console.log('It\'s saved!');
        });

    });
}); 

Hope this solves your query :)

almost 3 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recomiéndame algunas ofertas
Necesito ayuda