Cloud File Sharing using Python
Gofile
Gofile is a free, anonymous file-sharing platform that enables users to upload and share files without sign-ups. It provides user privacy and security by offering many features like anonymous uploads, file deletion, limited lifespan, and no tracking facility. Users can upload various formats and generate shareable links to share the files.
To install the Gofile module, run the following command in the Terminal Window:
pip install gofile
Working Procedure of GoFile:
- Using accounts, files, and folders, the Gofile system controls a productive file storage system. Its API enables effective file management and organization. A root folder exists for each account and cannot be removed.
- A guest account and root folder are formed when a file is uploaded without any parameters being specified, and the file is then uploaded to a new folder inside the root folder.
- Upload the first file, get the folderId from the response, and then upload each further file one at a time while including the folderId as a parameter.
API:
API is an abbreviation for “Application Programming Interface.” Different software applications can connect and interact with one another through a set of rules, protocols, and tools. Now we can see the API’s used:
GET https://api.gofile.io/getServer
- Returns the best server available to receive files.
Curl example:
curl https://api.gofile.io/getServer
JavaScript example:
fetch('https://api.gofile.io/getServer')
.then(response => response.json())
.then(data => {
if (data.status === 'ok') {
console.log(data.data.server)
}
})
.catch(error => console.error(error))
Response Example:
fetch('https://api.gofile.io/getServer')
.then(response => response.json())
.then(data => {
if (data.status === 'ok') {
console.log(data.data.server)
}
})
.catch(error => console.error(error))
POST https://(server}.gofile.io/uploadFile
- Upload one file on a specific server.
- The file will be added to the folder with the specified folderId.
Parameters:
- File (required) :
- Must contain one file.
- If you want to upload more than one file, use uploadFile once more and include the folderId of the first file you uploaded.
- Token (optional) :
- The access token of an account. Can be retrieved from the profile page.
- If valid, the file will be added to this account.
- If undefined, a guest account will be created to receive the file.
- FolderId (optional) :
- The ID of a folder.
- If valid, the file will be added to this folder.
- If undefined, a new folder will be created to receive the file.
- When using the folderId, you must pass the account token.
Curl example:
curl -F file=@someFile.txt https://store1.gofile.io/uploadFile
JavaScript example:
const formData = new FormData();
formData.append('file', fileInput.files[0]);
fetch('https://store1.gofile.io/uploadFile', {
method: 'POST',
body: formData,
})
.then(response => response.json())
.then(data => {
if (data.status === 'ok') {
console.log(data.data)
}
})
.catch(error => console.error(error))
Response Example:
{
"status": "ok",
"data": {
"downloadPage": "https://gofile.io/d/Z19n9a",
"code": "Z19n9a",
"parentFolder": "3dbc2f87-4c1e-4a81-badc-af004e61a5b4",
"fileId": "4991e6d7-5217-46ae-af3d-c9174adae924",
"fileName": "example.mp4",
"md5": "10c918b1d01aea85864ee65d9e0c2305"
}
}
Code:
# Import the 'gofile' module as 'go'
import gofile as go
# Define a function 'Store_Files' that takes a 'file' as input
def Store_Files(file):
# Get the current server for file upload using 'getServer()' function from 'gofile' module
cur_server = go.getServer()
# Print the current server to the console
print(cur_server)
# Upload the file using 'uploadFile()' function from 'gofile' module
# 'file' is the path to the file you want to upload
url = go.uploadFile(file)
# Print the download link to the uploaded file
print("Download Link: ", url["downloadPage"])
# Call the 'Store_Files' function and pass the path to the file you want to upload
Store_Files(r"C:\Users\DELL\Desktop\INTERNSHIP\Bg (1).jpg")
# Contributed by PL VISHNUPPRIYAN
Working of the code:
- The code imports the ‘gofile’ module and defines a function called ‘Store_Files’.
- It retrieves the server, uploads the file, retrieves the download link, and calls the ‘Store_Files’ function with the file path “C:\Users\DELL\Desktop\INTERNSHIP\Bg (1).jpg” as an argument.
- This is an example that demonstrates how to interact with the Gofile API and upload files using the Python ‘gofile’ module.
- After getting the Download Link in your Terminal Window, open the link to see your file uploaded in GoFile platform.
Input File:
Output:
How to do Cloud File Sharing using Python?
In this article, we will see how to share files online using a free, secure platform called GoFile. We can make it available for anyone through the link generated with the help of Python. Gofile is a platform for sharing and storing files. You have no restrictions on how much content you can save or share. Gofile can accommodate your needs whether you want to save your data in the file manager, share your files to pals, or broadcast your material to thousands of people.