How to use the imgur.uploadFile function in imgur

To help you get started, we’ve selected a few imgur examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DT42 / BerryNet / line.js View on Github external
client.on('message', (t, m) => {
  const size = m.length;
  log(`client on topic ${t}, received ${size} bytes.`)

  if (t === topicDashboardInferenceResult) {
    const result = m.toString();
    LINEClient.pushMessage(targetUserID, { type: 'text', text: result });
    return;
  }

  // save image to file and upload it to imgur for display in LINE message
  const snapshot_path = m.toString();
  imgur.uploadFile(snapshot_path)
    .then((json) => {
      var imgurLink = json.data.link;
      imgurLink = imgurLink.replace('http:\/\/', 'https:\/\/');
      log(`An image has been uploaded to imgur. link: ${imgurLink}`);

      // Image can only be delivered via 'https://' URL, 'http://' doesn't work
      LINEClient.pushMessage(targetUserID, { type: 'image',
                                             originalContentUrl: imgurLink,
                                             previewImageUrl: imgurLink })
        .then((v) => {
          log(`A message sent to ${targetUserID} successfully.`);
        })
        .catch((err) => {
          log(`An error occurred, ${err}.`);
        });
    })
github FruitieX / teleirc / src / tg / imgur-utils.js View on Github external
const filePath = await tg.downloadFile(fileId, downloadDirPath);

            const fileContentBuffer = await fs.readFile(filePath);
            const md5Hash = md5(fileContentBuffer);

            if (!linkCache.has(md5Hash)) {

                /* Imgur doesn't allow webp, so convert them to png. */
                let uploadableFilePath = filePath;
                if (path.extname(filePath) === '.webp') {
                    const convertedFilePath = filePath + '.png';
                    uploadableFilePath = await convertWebpToPng(filePath, convertedFilePath);
                }

                const imgurData = await imgur.uploadFile(uploadableFilePath);

                linkCache.set(md5Hash, imgurData.data.link);

                /* Not waiting for this write, because it doesn't matter when it
                * finishes. */
                fs.writeJson(linkCacheFilePath, [...linkCache]);
            }
            const imgurLink = linkCache.get(md5Hash);

            /* Cleanup. Not waiting for this. */
            fs.remove(downloadDirPath);

            return imgurLink;

        } catch (error) {
            logger.error(error);
github 1MB / 1mb-cli / src / commands / deploy.js View on Github external
cwd = process.cwd() + '/build/'
        }
        else {
        	cwd = process.cwd();
        }

        let image_files = []
        let images = []
        await glob.glob(['*.png', '*/*.png', '*.jpg', '*/*.jpg', '*.gif', '*/*.gif'], {cwd: cwd}).then(imgs => {
            for (var i = imgs.length - 1; i >= 0; i--) {
                image_files[i] = `${imgs[i]}`
            }
        })

        for (var i = image_files.length - 1; i >= 0; i--) {
            await imgur.uploadFile(`${cwd}/${image_files[i]}`).then(json => {
                images[i] = {
                    path: image_files[i],
                    url: json.data.link
                }
            })
        }

        // check if pro before pushing files | might use this later
        // let pro = request.post('https://api.1mb.site', {
        //     form: {
        //         action: 'pro',
        //         site: username,
        //         key: key
        //     }
        // }, (error, response, body) => {
        // 	return body.error || error;
github frontend / generator-toolbox / generators / app / templates / tasks / tests-regression.js View on Github external
files.forEach(function(file){
        imgur.uploadFile(testConfig.comparisonPath + file)
          .then(function (json) {
            $.util.log($.util.colors.red(file) + $.util.colors.cyan(' -> ') + json.data.link);

          })
          .catch(function (err) {
            console.error(err.message);
          });
      });
    }
github paypal / paypal-checkout-components / test / screenshot / lib / image.js View on Github external
export async function uploadToImgur(path : string) : Promise {
    let result = await imgur.uploadFile(path);
    if (result) {
        return result.data.link;
    }
}
github Hydrog3n / upload-screenshot / services / imgur.js View on Github external
Imgur.prototype.upload = function(path,callback) {

  img.setClientId(this.service.clientId);

  img.uploadFile(path)
    .then(function (json) {
    callback(json.data.link);
    })
    .catch(function (err) {
      console.error(err);
      notifier.notify({
        'title': 'Error !',
        'message': err
      });
    });
};
github te-emprego / api / src / controller / user.js View on Github external
const uploadProfilePicture = async (req, res) => {
  const { avatar } = req.files;
  if (avatar.size > 100000) {
    return res
      .status(400)
      .send({ message: 'A imagem não pode ter mais que 1Mb' });
  }
  imgur
    .uploadFile(avatar.path)
    .then(async (json) => {
      const { link } = json.data;
      const { me } = req;

      const user = await User.findOne({ _id: me._id });
      user.avatar = link;
      user.save();

      helpers.unlink(avatar.path);

      return res
        .status(200)
        .send({
          user,
          message: 'Avatar salvo com sucesso.',
github ewnd9 / record-desktop / src / main / utils.js View on Github external
export const uploadFile = file => {
  notify('Uploading...');

  imgur.uploadFile(file)
    .then(function (json) {
      clipboard.writeText(json.data.link);
      notify('Copied Url to Clipboard');
    });
};
github DIYgod / RSSHub / routes / telegram / stickerpack.js View on Github external
const fileResponse = await axios({
                    method: 'get',
                    url: `https://api.telegram.org/file/bot${config.telegram.token}/${path}`,
                    responseType: 'arraybuffer',
                });

                const filePath = `tmp/${item.file_id}.png`;

                await sharp(fileResponse.data)
                    .png()
                    .toFile(filePath);

                let imgurResponse;
                try {
                    imgurResponse = await imgur.uploadFile(filePath);
                } catch (e) {
                    logger.error(`Error in imgur upload ${filePath}`, e);
                }
                const link = imgurResponse.data.link;

                fs.unlink(filePath, (e) => {
                    logger.error(`Error in remove ${filePath}`, e);
                });

                ctx.cache.set(key, link, cacheDays * 24 * 60 * 60);
                return Promise.resolve(link);
            }
        })
    );

imgur

Unofficial JavaScript library for Imgur

AGPL-3.0
Latest version published 3 months ago

Package Health Score

72 / 100
Full package analysis