How to do Cloud File Sharing using Python?
Last Updated :
06 Jun, 2024
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.
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:
JavaScript
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:
JavaScript
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:
- 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.
- 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.
- 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 [email protected] https://store1.gofile.io/uploadFile
JavaScript example:
JavaScript
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:
JavaScript
{
"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:
Python
# 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:

Input: The file that is uploaded to the Cloud Storage
Output:

Output: in Terminal Window

Output: The uploaded file is visible in the Cloud Storage
Similar Reads
File Sharing App using Python
Computer Networks is an important topic and to understand the concepts, practical application of the concepts is needed. In this particular article, we will see how to make a simple file-sharing app using Python. An HTTP Web Server is software that understands URLs (web address) and HTTP (the protoc
4 min read
How to get size of folder using Python?
In this article, we are going to discuss various approaches to get the size of a folder using python. To get the size of a directory, the user has to walk through the whole folder and add the size of each file present in that folder and will show the total size of the folder. Steps to be followed: I
3 min read
How to Download and Upload Files in FTP Server using Python?
Prerequisite: FTP, ftplib Here, we will learn how to Download and Upload Files in FTP Server Using Python. Before we get started, first we will understand what is FTP. FTP(File Transfer Protocol) File Transfer Protocol(FTP) is an application layer protocol that moves files between local and remote f
3 min read
How to hide sensitive credentials using Python
Have you ever been in a situation where you are working on a python project need to share your code with someone or you are hosting your code in a public repository but don't want to share the sensitive credentials so it isn't exploited by a random user? For example, you are making a web app in Djan
6 min read
How To Upload And Download Files From AWS S3 Using Python?
Pre-requisite: AWS and S3 Amazon Web Services (AWS) offers on-demand cloud services which means it only charges on the services we use (pay-as-you-go pricing). AWS S3 is a cloud storage service from AWS. S3 stands for 'Simple Storage Service. It is scalable, cost-effective, simple, and secure. We ge
3 min read
How To Send Files Using Python Built-In Http Server
Python's built-in HTTP server offers a straightforward way to share files over a local network or the internet without the need for complex setups. In this tutorial, we'll walk through the step-by-step process of using Python's built-in HTTP server to send files to clients. Setting Up the HTTP Serve
2 min read
How to List all Files and Directories in FTP Server using Python?
FTP ( File Transfer Protocol ) is set of rules that computer follows to transfer files across computer network. It is TCP/IP based protocol. FTP lets clients share files. FTP is less secure because of files are shared as plain text without any encryption across the network. It is possible using pyth
2 min read
How to Make API Call Using Python
APIs (Application Programming Interfaces) are an essential part of modern software development, allowing different applications to communicate and share data. Python provides a popular library i.e. requests library that simplifies the process of calling API in Python. In this article, we will see ho
3 min read
How to copy file in Python3?
Prerequisites: Shutil When we require a backup of data, we usually make a copy of that file. Python supports file handling and allows users to handle files i.e., to read and write files, along with many other file handling options, to operate on files. Here we will learn how to copy a file using Pyt
2 min read
How to Download Files from Urls With Python
Here, we have a task to download files from URLs with Python. In this article, we will see how to download files from URLs using some generally used methods in Python. Download Files from URLs with PythonBelow are the methods to Download files from URLs with Python: Using 'requests' ModuleUsing 'url
2 min read