Skip to content

Instantly share code, notes, and snippets.

@ZenulAbidin
Created May 12, 2020 11:36
Show Gist options
  • Save ZenulAbidin/d37413575d91fd0e58472c030d55163c to your computer and use it in GitHub Desktop.
Save ZenulAbidin/d37413575d91fd0e58472c030d55163c to your computer and use it in GitHub Desktop.
Uploads files to GoFile
const fetch = require("node-fetch");
const util = require("util");
const path = require("path");
const fs = require("fs");
const homedir = require("os").homedir();
const process = require("process");
try {
filePath = process.argv[1];
}
catch (error) {
filePath = path.join(homedir, "images", "asmol.tar.xz");
}
const bestServerURL = "https://apiv2.gofile.io/getServer"
const FormData = require('form-data');
const form = new FormData();
const doUpload = url => {
fs.readFile(filePath, {encoding: 'utf-8'}, function(err, data) {
if (!err) {
try {
form.append("filesUploaded", fs.createReadStream(filePath));
form.append("email", "<REDACTED>");
const response = fetch(url, {
method: "POST",
body: form
}).then(function (r) {return r.json()} ).then(
function(json) {
console.log(json);
}
);
} catch (error) {
console.log(error);
}
} else {
console.log(err);
}
});
}
const getBestServer = async url => {
try {
const response = await fetch(url);
const json = await response.json();
uploadURL = util.format("https://%s.gofile.io/upload", json["data"]["server"]);
console.log(json);
console.log(uploadURL);
doUpload(uploadURL);
} catch (error) {
console.log(error);
}
};
getBestServer(bestServerURL);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment