### Build and Start tfLink MCP from Source Source: https://tmpfile.link/temp-file-share-mcp Installs dependencies, builds the project, and starts the tfLink MCP server from its source code. This is an alternative to the npx installation. ```bash npm install npm run build npm run start ``` -------------------------------- ### Example Prompts for Uploading Files Source: https://tmpfile.link/temp-file-share-mcp These examples demonstrate how to instruct the MCP tool to upload local files. They cover single file uploads, multiple file uploads, and uploads using absolute paths, showcasing the natural language interface for file sharing. ```shell # Upload a local file "Please use mcp tool to upload \`/Users/chris/Downloads/xx.log\` and get a temporary download link." # Upload multiple files "Upload these files using the MCP tool: - /home/user/report.docx - /home/user/presentation.pptx" # Upload with absolute path "Upload /tmp/data.json using the MCP upload tool and share the link" ``` -------------------------------- ### Install tfLink MCP via npx Source: https://tmpfile.link/temp-file-share-mcp Installs the tfLink MCP package using npx, the recommended method for quick setup. This command downloads and runs the latest version of the package. ```bash npx -y temp-file-share-mcp@latest ``` -------------------------------- ### Install and Use tfLink Client (Python) Source: https://tmpfile.link/blog/python-automated-file-upload-guide Provides the basic commands to install the tfLink library using pip and a minimal code example to instantiate the client, upload a file, and print the resulting download link. ```bash pip install tflink ``` ```python from tflink import TFLinkClient client = TFLinkClient() result = client.upload('file.pdf') print(result.download_link) # Share this URL ``` -------------------------------- ### JavaScript/Node.js Upload Example Source: https://tmpfile.link/blog/api-temporary-upload-guide Example of how to upload a file using the tfLink API with JavaScript's Fetch API, supporting both anonymous and authenticated uploads. ```APIDOC ## JavaScript/Node.js Upload Example ### Description This example demonstrates how to upload a file to tfLink using the browser's Fetch API. It handles both anonymous and authenticated upload scenarios by conditionally adding authentication headers. ### Method POST ### Endpoint https://tmpfile.link/api/upload ### Parameters #### Request Body - **file** (File object) - The file to upload, typically obtained from an `` element. - **userCredentials** (object) - Optional. An object containing `userId` and `authToken` for authenticated uploads. - **userId** (string) - Your user ID. - **authToken** (string) - Your authentication token. ### Request Example ```javascript async function uploadToTfLink(file, userCredentials = null) { const formData = new FormData(); formData.append('file', file); const headers = {}; if (userCredentials) { headers['X-User-Id'] = userCredentials.userId; headers['X-Auth-Token'] = userCredentials.authToken; } try { const response = await fetch('https://tmpfile.link/api/upload', { method: 'POST', headers: headers, body: formData }); if (!response.ok) { throw new Error(`Upload failed: ${response.status} ${response.statusText}`); } const result = await response.json(); return { success: true, data: result }; } catch (error) { console.error('Upload error:', error); return { success: false, error: error.message }; } } // --- Usage Examples --- // Assuming 'fileInput' is an HTML input element of type 'file' // const fileInput = document.getElementById('myFileInput'); // const fileToUpload = fileInput.files[0]; // Example 1: Anonymous Upload // const anonymousResult = await uploadToTfLink(fileToUpload); // if (anonymousResult.success) { // console.log('Anonymous upload successful:', anonymousResult.data); // } else { // console.error('Anonymous upload failed:', anonymousResult.error); // } // Example 2: Authenticated Upload // const credentials = { // userId: 'YOUR_USER_ID', // authToken: 'YOUR_AUTH_TOKEN' // }; // const authenticatedResult = await uploadToTfLink(fileToUpload, credentials); // if (authenticatedResult.success) { // console.log('Authenticated upload successful:', authenticatedResult.data); // } else { // console.error('Authenticated upload failed:', authenticatedResult.error); // } ``` ### Response See the general response format for the `POST /api/upload` endpoint. ``` -------------------------------- ### Install MCP Server Package (Node.js) Source: https://tmpfile.link/about Instructions for installing the 'temp-file-share-mcp' Node.js package, which serves as a Model Context Protocol server for AI assistants to integrate file sharing. ```bash npm install temp-file-share-mcp ``` -------------------------------- ### Install and Use Python CLI for Upload Source: https://tmpfile.link/about Shows how to install the official Python CLI tool for tfLink and use it to upload files. This simplifies the file-sharing process for scripting and terminal users. ```bash pip install tflink ``` ```bash tflink upload file.pdf ``` -------------------------------- ### Automatic Configuration Output for MCP Client Source: https://tmpfile.link/temp-file-share-mcp Example output from the tfLink MCP server indicating its status and providing a configuration template for MCP clients. This includes connection details and environment variables. ```json temp-file-share-mcp version 0.1.14 temp-file-share-mcp running in stdio mode Run via: npx -y temp-file-share-mcp@latest Connect using an MCP client that spawns this command. Example Cherry Studio config: { "mcpServers": { "temp-file-share-mcp": { "type": "stdio", "name": "temp-file-share-mcp", "description": "Upload a local file to tmpfile.link and receive a temporary download URL.", "command": "npx", "args": [ "-y", "temp-file-share-mcp@latest" ], "env": { "TFLINK_USER_ID": "", "TFLINK_AUTH_TOKEN": "" } } } } ``` -------------------------------- ### cURL Authenticated File Upload Source: https://tmpfile.link/blog/upload-file-temporary-link-best-practices Shows how to upload files with user authentication headers using cURL. Includes examples for single authenticated uploads and batch uploads of multiple files. ```bash # With user authentication curl -X POST \ -H "X-User-Id: your-user-id" \ -H "X-Auth-Token: your-auth-token" \ -F "file=@confidential.doc" \ https://tmpfile.link/api/upload # Batch upload multiple files for file in *.pdf; do echo "Uploading $file..." curl -X POST \ -H "X-User-Id: your-user-id" \ -H "X-Auth-Token: your-auth-token" \ -F "file=@$file" \ https://tmpfile.link/api/upload done ``` -------------------------------- ### API Key Authentication - Upload Source: https://tmpfile.link/blog/api-temp-backup Demonstrates how to authenticate and upload a file using an API key. ```APIDOC ## POST /upload ### Description Uploads a file to the temporary file service using API key authentication. ### Method POST ### Endpoint https://api.example.com/upload ### Parameters #### Query Parameters - **file** (file) - Required - The binary file data to upload. - **expires_in** (integer) - Optional - Expiration time in seconds (default: 86400). - **password** (string) - Optional - Password protection for the uploaded file. - **max_downloads** (integer) - Optional - Maximum number of allowed downloads. #### Request Body This endpoint uses `multipart/form-data` for file uploads. ### Request Example ```bash curl -X POST https://api.example.com/upload \ -H "Authorization: Bearer YOUR_API_KEY" \ -F "file=@document.pdf" ``` ### Response #### Success Response (200) - **message** (string) - Confirmation message of successful upload. - **file_url** (string) - The URL to access the uploaded file. #### Response Example ```json { "message": "File uploaded successfully.", "file_url": "https://api.example.com/download/unique_file_id" } ``` ``` -------------------------------- ### Authentication and Rate Limiting Source: https://tmpfile.link/blog/upload-file-temporary-link-best-practices Details on how to authenticate API requests and the implemented rate limiting policies. ```APIDOC ## Authentication and Rate Limiting ### Authentication Requests can be authenticated by providing `X-User-Id` and `X-Auth-Token` headers. If these headers are not provided, uploads are considered anonymous but are subject to stricter rate limits. ### Rate Limiting The API enforces rate limiting to prevent abuse. For authenticated users, the limit is 10 uploads per 15 minutes per IP. Anonymous uploads may have stricter limits. #### cURL Examples **Anonymous Upload:** ```bash # Basic file upload curl -X POST -F "file=@document.pdf" https://tmpfile.link/api/upload # With progress bar curl -X POST -F "file=@large-file.zip" --progress-bar https://tmpfile.link/api/upload # Save response to file curl -X POST -F "file=@image.jpg" -o upload-result.json https://tmpfile.link/api/upload ``` **Authenticated Upload:** ```bash # With user authentication curl -X POST -H "X-User-Id: your-user-id" -H "X-Auth-Token: your-auth-token" -F "file=@confidential.doc" https://tmpfile.link/api/upload # Batch upload multiple files (example loop) for file in *.pdf; do echo "Uploading $file..." curl -X POST \ -H "X-User-Id: your-user-id" \ -H "X-Auth-Token: your-auth-token" \ -F "file=@$file" \ https://tmpfile.link/api/upload done ``` ``` -------------------------------- ### Authenticated Upload JSON Response Example Source: https://tmpfile.link/ An example of the JSON response after an authenticated file upload to tmpfile.link. The response structure is similar to anonymous uploads but indicates the file is stored under the user's account. The 'uploadedTo' field specifies the user ID. ```json { "fileName": "document.pdf", "downloadLink": "https://d.tmpfile.link/users/YOUR_USER_ID/2025-07-31/uuid-example/document.pdf", "downloadLinkEncoded": "https://d.tmpfile.link/users%2FYOUR_USER_ID%2F2025-07-31%2Fuuid-example%2Fdocument.pdf", "size": 2048000, "type": "application/pdf", "uploadedTo": "user: YOUR_USER_ID" } ``` -------------------------------- ### Anonymous Upload JSON Response Example Source: https://tmpfile.link/ An example of the JSON response received after an anonymous file upload to tmpfile.link. It includes details like the file name, encoded and unencoded download links, file size, type, and upload destination. Files uploaded anonymously are deleted after 7 days. ```json { "fileName": "my file 文件.png", "downloadLink": "https://d.tmpfile.link/public/2025-07-31/a1b2c3d4-e5f6-7890-abcd-ef1234567890/my file 文件.png", "downloadLinkEncoded": "https://d.tmpfile.link/public/2025-07-31/a1b2c3d4-e5f6-7890-abcd-ef1234567890/my%20file%20%E6%96%87%E4%BB%B6.png", "size": 102400, "type": "image/png", "uploadedTo": "public" } ``` -------------------------------- ### OAuth 2.0 Integration - Upload Source: https://tmpfile.link/blog/api-temp-backup Demonstrates how to authenticate and upload a file using an OAuth 2.0 access token. ```APIDOC ## POST /upload (OAuth 2.0) ### Description Uploads a file to the temporary file service using OAuth 2.0 authentication. ### Method POST ### Endpoint https://api.example.com/upload ### Parameters #### Query Parameters - **file** (file) - Required - The binary file data to upload. - **expires_in** (integer) - Optional - Expiration time in seconds (default: 86400). - **password** (string) - Optional - Password protection for the uploaded file. - **max_downloads** (integer) - Optional - Maximum number of allowed downloads. #### Request Body This endpoint uses `multipart/form-data` for file uploads. ### Request Example ```bash curl -X POST https://api.example.com/upload \ -H "Authorization: Bearer ACCESS_TOKEN" \ -F "file=@image.jpg" \ -F "expires_in=3600" ``` ### Response #### Success Response (200) - **message** (string) - Confirmation message of successful upload. - **file_url** (string) - The URL to access the uploaded file. #### Response Example ```json { "message": "File uploaded successfully.", "file_url": "https://api.example.com/download/unique_file_id" } ``` ``` -------------------------------- ### POST /api/upload Source: https://tmpfile.link/blog/upload-file-temporary-link-best-practices Handles file uploads, generates temporary download links, and schedules cleanup. Supports authentication and rate limiting. ```APIDOC ## POST /api/upload ### Description This endpoint allows users to upload files. Upon successful upload, it generates a temporary download link that expires after a specified period (default is 7 days). It also handles file validation, unique file naming, and schedules automatic cleanup of uploaded files. ### Method POST ### Endpoint /api/upload ### Parameters #### Query Parameters None #### Request Body - **file** (file) - Required - The file to be uploaded. This should be sent as `multipart/form-data`. ### Request Example ```bash curl -X POST -F "file=@document.pdf" https://tmpfile.link/api/upload ``` ### Response #### Success Response (200) - **fileName** (string) - The original name of the uploaded file. - **downloadLink** (string) - A temporary URL to download the uploaded file. - **size** (integer) - The size of the uploaded file in bytes. - **type** (string) - The MIME type of the uploaded file. - **expiresIn** (string) - The duration until the download link expires (e.g., '7 days'). #### Response Example ```json { "fileName": "document.pdf", "downloadLink": "https://tmpfile.link/download/path/to/your/file.pdf", "size": 102400, "type": "application/pdf", "expiresIn": "7 days" } ``` #### Error Response (400) - **error** (string) - Description of the error (e.g., 'No file provided', 'File type not allowed'). #### Error Response (500) - **error** (string) - 'Upload failed' if an internal server error occurs. ``` -------------------------------- ### Development Commands for MCP Server Source: https://tmpfile.link/temp-file-share-mcp This section outlines essential npm commands for developers working on the MCP server. It includes commands for linting the code, running tests, and building the TypeScript project, facilitating contributions and maintenance. ```shell # Lint the code npm run lint # Run tests npm test # Build TypeScript npm run build ``` -------------------------------- ### POST /api/upload Source: https://tmpfile.link/blog/upload-file-temporary-link-best-practices Upload a file and receive a temporary download link. The API accepts a multipart/form-data request with the file to be uploaded. ```APIDOC ## POST /api/upload ### Description Upload a file and receive a temporary download link. The API accepts a multipart/form-data request with the file to be uploaded. ### Method POST ### Endpoint https://tmpfile.link/api/upload ### Parameters #### Query Parameters - **userId** (string) - Optional - The ID of the user initiating the upload. - **authToken** (string) - Optional - The authentication token for the user. #### Request Body - **file** (file) - Required - The file to be uploaded. ### Request Example ```bash curl -X POST -F "file=@presentation.pdf" https://tmpfile.link/api/upload ``` ### Response #### Success Response (200) - **fileName** (string) - The name of the uploaded file. - **downloadLink** (string) - The direct temporary download URL for the file. - **downloadLinkEncoded** (string) - An URL-encoded version of the download link. - **size** (integer) - The size of the uploaded file in bytes. - **type** (string) - The MIME type of the file. - **uploadedTo** (string) - The destination or storage type where the file was uploaded. #### Response Example ```json { "fileName": "presentation.pdf", "downloadLink": "https://d.tmpfile.link/public/2024-12-11/uuid/presentation.pdf", "downloadLinkEncoded": "https://d.tmpfile.link/public%2F2024-12-11%2Fuuid%2Fpresentation.pdf", "size": 5242880, "type": "application/pdf", "uploadedTo": "public" } ``` ``` -------------------------------- ### Batch File Upload and Sharing with tfLink CLI Source: https://tmpfile.link/blog/claude-code-ssh-remote-development This example demonstrates how to use a hypothetical `tfup` command-line tool (assumed to be a wrapper for tfLink uploads) to upload multiple files and then share their URLs in a development context, such as with an AI coding assistant. This streamlines the process of providing multiple design assets or data files for review or implementation. ```bash # On your local machine tfup design1.png tfup design2.png tfup design3.png # In your SSH session with Claude Code: You: I need to implement these three designs: 1. https://d.tmpfile.link/.../design1.png 2. https://d.tmpfile.link/.../design2.png 3. https://d.tmpfile.link/.../design3.png Please analyze all three and create a cohesive implementation. ``` -------------------------------- ### Successful File Upload Response Source: https://tmpfile.link/temp-file-share-mcp This is an example of a successful response after uploading a file using the MCP tool. It includes the filename, size, a direct download link, an encoded link, and the expiration time of the shared file. ```text ✅ File uploaded successfully! 📁 Filename: my log 日志.log 📏 Size: 2.4 MB 🔗 Download Link: https://d.tmpfile.link/public/2025-09-20/uuid-here/my log 日志.log 🔗 Encoded Link: https://d.tmpfile.link/public/2025-09-20/uuid-here/my%20log%20%E6%97%A5%E5%BF%97.log ⏰ Expires: September 27, 2025 (7 days) You can share this link with anyone. The file will be automatically deleted after 7 days for privacy. ``` -------------------------------- ### cURL Anonymous File Upload Source: https://tmpfile.link/blog/upload-file-temporary-link-best-practices Demonstrates how to perform anonymous file uploads to the tmpfile.link API using cURL. Examples include basic upload, with a progress bar, and saving the response to a file. ```bash # Basic file upload curl -X POST \ -F "file=@document.pdf" \ https://tmpfile.link/api/upload # With progress bar curl -X POST \ -F "file=@large-file.zip" \ --progress-bar \ https://tmpfile.link/api/upload # Save response to file curl -X POST \ -F "file=@image.jpg" \ -o upload-result.json \ https://tmpfile.link/api/upload ``` -------------------------------- ### Create Workflow Link and Update Workflow (JavaScript) Source: https://tmpfile.link/blog/one-time-file-upload-links-secure-sharing Generates a one-time sharing link by uploading a file and then updates a workflow system with the generated link and its details. It relies on `fetch` API and a function `updateWorkflow`. ```javascript const createWorkflowLink = async (fileData, workflowId) => { const response = await fetch('/upload-once', { method: 'POST', body: fileData }); const { oneTimeLink } = await response.json(); // Update workflow with secure link await updateWorkflow(workflowId, { documentLink: oneTimeLink, linkCreated: new Date(), accessType: 'one-time' }); return oneTimeLink; }; ``` -------------------------------- ### Optimized tmpfile.link API Response Format Source: https://tmpfile.link/blog/upload-file-temporary-link-best-practices An example of an optimized response format from the tmpfile.link API after a successful upload. It includes success status, file details, various download links (direct, encoded, QR code), expiration information, and upload metadata. ```json { "success": true, "file": { "name": "document.pdf", "size": 2048000, "type": "application/pdf" }, "links": { "download": "https://d.tmpfile.link/temp/abc123/document.pdf", "downloadEncoded": "https://d.tmpfile.link/temp%2Fabc123%2Fdocument.pdf", "qrCode": "https://tmpfile.link/qr/abc123" }, "expiration": { "timestamp": "2024-12-18T10:30:00Z", "humanReadable": "7 days from now" }, "upload": { "timestamp": "2024-12-11T10:30:00Z", "method": "api", "authenticated": true } } ``` -------------------------------- ### Upload File and Get Temporary Link (Python) Source: https://tmpfile.link/blog/upload-file-temporary-link-best-practices This Python function demonstrates how to upload a file using the requests library and retrieve a temporary download link from the tfLink API. It includes optional headers for user authentication and handles potential upload failures. ```python import requests def upload_file_get_temp_link(file_path, user_id=None, auth_token=None): url = "https://tmpfile.link/api/upload" headers = {} if user_id and auth_token: headers['X-User-Id'] = user_id headers['X-Auth-Token'] = auth_token with open(file_path, 'rb') as file: files = {'file': file} response = requests.post(url, files=files, headers=headers) if response.status_code == 200: result = response.json() return result['downloadLink'] else: raise Exception(f"Upload failed: {response.text}") # Usage temp_link = upload_file_get_temp_link("report.pdf") print(f"Temporary download link: {temp_link}") ``` -------------------------------- ### CI/CD Integration for Sharing Build Artifacts (Bash/Shell) Source: https://tmpfile.link/blog/temporary-file-upload-vs-permanent-cloud-storage This snippet demonstrates how to integrate temporary file uploads into a CI/CD pipeline, specifically for sharing build artifacts. It uses `curl` to upload a file to a temporary service and `jq` to parse the JSON response for the download link, which is then posted to Slack. This is useful for distributing test builds to QA teams without permanent storage. ```bash # GitHub Actions workflow - name: Share build with QA run: | # Upload build artifact DOWNLOAD_URL=$(curl -s -F "file=@./dist/app-${GITHUB_SHA:0:8}.zip" \ https://tmpfile.link/api/upload | jq -r .downloadLink) # Notify QA team echo "QA Build ready: $DOWNLOAD_URL" | \ curl -X POST -H "Content-Type: application/json" \ -d "{\"text\":\"New build available: $DOWNLOAD_URL\"}" \ $SLACK_WEBHOOK_URL ``` -------------------------------- ### Upload File and Get Temporary Link via tfLink API Source: https://tmpfile.link/blog/temporary-download-link-guide This cURL command demonstrates how to upload a file using the tfLink API and receive a temporary download link in the response. The request is a POST request with the file data sent as form-data. The response is a JSON object containing the file name, download link, size, and type. ```bash curl -X POST \ -F "file=@/path/to/your/file.pdf" \ https://tmpfile.link/api/upload # Returns JSON with temporary download link { "fileName": "document.pdf", "downloadLink": "https://d.tmpfile.link/public/2024-12-12/uuid/document.pdf", "size": 2048000, "type": "application/pdf" } ``` -------------------------------- ### Install tflink Python Package Source: https://tmpfile.link/blog/python-automated-file-upload-guide This command installs the tflink Python package using pip. Ensure you have Python and pip installed on your system. This is the first step to enabling automated file uploads in your Python scripts. ```bash pip install tflink ``` -------------------------------- ### CI/CD Integration - GitHub Actions Upload Source: https://tmpfile.link/blog/free-temporary-file-upload-no-signup An example of integrating tfLink file uploads into a GitHub Actions workflow. This snippet shows how to upload build artifacts and output the download URL to the job summary. ```shell # GitHub Actions example - name: Upload build artifacts run: | DOWNLOAD_URL=$(curl -s -F "file=@./dist/app.zip" https://tmpfile.link/api/upload | jq -r .downloadLink) echo "Build available at: $DOWNLOAD_URL" >> $GITHUB_STEP_SUMMARY ``` -------------------------------- ### Anonymous File Upload using Python (tflink package) Source: https://tmpfile.link/ Uploads a file anonymously using the official tflink Python package. First, install the package using 'pip install tflink'. Then, instantiate TFLinkClient without credentials and call the upload method with the file path. ```python from tflink import TFLinkClient client = TFLinkClient() result = client.upload('document.pdf') print(f"Download: {result.download_link}") ``` -------------------------------- ### Temporary File Upload Service Initialization Source: https://tmpfile.link/blog/temporary-file-upload-direct-link-security Initializes the TemporaryFileUploadService by setting up its dependencies, including cloud storage, a direct link generator, a file security validator, a direct link monitor, and a file cleanup service. Configuration details for each service are passed via the constructor. ```javascript // Complete temporary file upload with direct links class TemporaryFileUploadService { constructor(config) { this.storage = new CloudStorageProvider(config.storage); this.linkGenerator = new DirectLinkGenerator(config.secrets); this.security = new FileSecurityValidator(config.security); this.monitor = new DirectLinkMonitor(config.logging); this.cleanup = new FileCleanupService(config.cleanup); } async uploadFile(file, userContext) { ``` -------------------------------- ### Hybrid File Handling Workflow (JavaScript) Source: https://tmpfile.link/blog/temporary-file-upload-vs-permanent-cloud-storage Demonstrates a hybrid file handling workflow using JavaScript, illustrating how to upload files to either a temporary service or permanent storage based on their intended purpose. It includes a function to schedule automatic archival from temporary to permanent storage. ```javascript const handleFileUpload = async (file, purpose) => { if (purpose === 'temporary-share') { // Use temporary upload for quick sharing return await uploadToTempService(file); } else if (purpose === 'archive') { // Use permanent storage for long-term retention return await uploadToPermanentStorage(file); } else if (purpose === 'transfer-then-archive') { // Upload to temporary first, then migrate to permanent const tempLink = await uploadToTempService(file); // Schedule migration to permanent storage await scheduleArchival(file, tempLink); return tempLink; } }; // Automated migration workflow const scheduleArchival = async (file, tempLink) => { // Wait for confirmation or deadline setTimeout(async () => { if (await shouldArchive(file)) { await migrateToPermantentStorage(tempLink, file); // Temporary file will auto-delete } }, 24 * 60 * 60 * 1000); // 24 hours }; ``` -------------------------------- ### POST /api/upload Source: https://tmpfile.link/blog/api-temporary-upload-guide Uploads a file temporarily using the tfLink API. Supports both anonymous and authenticated uploads. ```APIDOC ## POST /api/upload ### Description Uploads a file temporarily using the tfLink API. Supports both anonymous and authenticated uploads. Files are automatically cleaned up after a retention period. ### Method POST ### Endpoint https://tmpfile.link/api/upload ### Parameters #### Query Parameters None #### Headers - **X-User-Id** (string) - Optional - Your user ID for authenticated uploads. - **X-Auth-Token** (string) - Optional - Your authentication token for authenticated uploads. #### Request Body - **file** (file) - Required - The file to upload. Use `multipart/form-data` encoding. ### Request Example ``` POST /api/upload HTTP/1.1 Host: tmpfile.link Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW X-User-Id: YOUR_USER_ID X-Auth-Token: YOUR_AUTH_TOKEN ------WebKitFormBoundary7MA4YWxkTrZu0gW Content-Disposition: form-data; name="file"; filename="your-file.ext" Content-Type: application/octet-stream [Binary file content] ------WebKitFormBoundary7MA4YWxkTrZu0gW-- ``` ### Response #### Success Response (200) - **fileName** (string) - The name of the uploaded file. - **downloadLink** (string) - The direct download URL for the file. - **downloadLinkEncoded** (string) - An URL-encoded version of the download link. - **size** (integer) - The size of the uploaded file in bytes. - **type** (string) - The MIME type of the file. - **uploadedTo** (string) - Indicates where the file was uploaded (e.g., 'public' for anonymous, 'user: YOUR_USER_ID' for authenticated). #### Response Example (Anonymous) ```json { "fileName": "example.png", "downloadLink": "https://d.tmpfile.link/public/2024-12-07/a1b2c3d4-e5f6-7890-abcd-ef1234567890/example.png", "downloadLinkEncoded": "https://d.tmpfile.link/public%2F2024-12-07%2Fa1b2c3d4-e5f6-7890-abcd-ef1234567890%2Fexample.png", "size": 102400, "type": "image/png", "uploadedTo": "public" } ``` #### Response Example (Authenticated) ```json { "fileName": "document.pdf", "downloadLink": "https://d.tmpfile.link/users/YOUR_USER_ID/2024-12-07/uuid-example/document.pdf", "downloadLinkEncoded": "https://d.tmpfile.link/users%2FYOUR_USER_ID%2F2024-12-07%2Fuuid-example%2Fdocument.pdf", "size": 2048000, "type": "application/pdf", "uploadedTo": "user: YOUR_USER_ID" } ``` #### Error Handling - **400 Bad Request**: Invalid request format or missing file. - **401 Unauthorized**: Invalid or missing authentication credentials for authenticated uploads. - **413 Payload Too Large**: File size exceeds the 100MB limit. - **500 Internal Server Error**: Server-side error during upload. ``` -------------------------------- ### Node.js One-Time File Upload and Download Proxy Source: https://tmpfile.link/blog/one-time-file-upload-links-secure-sharing This Node.js code implements a web server using Express to handle file uploads and provide one-time download links. It utilizes Multer for file handling, node-fetch for interacting with an external upload service (tmpfile.link), and UUID for generating unique tokens. The service stores token data in memory (a Map), which includes the download link, file name, and expiration time. Uploaded files are sent to tmpfile.link, and a unique, one-time use URL is generated for the user. The download endpoint validates the token, checks for expiration, and redirects to the actual file. For production, in-memory storage should be replaced with a persistent solution like Redis. ```javascript const express = require('express'); const multer = require('multer'); const FormData = require('form-data'); const fetch = require('node-fetch'); const { v4: uuidv4 } = require('uuid'); const app = express(); const upload = multer({ storage: multer.memoryStorage() }); // In-memory token store (use Redis in production) const tokenStore = new Map(); // Upload endpoint app.post('/upload-once', upload.single('file'), async (req, res) => { try { // Upload to tfLink const formData = new FormData(); formData.append('file', req.file.buffer, req.file.originalname); const tfLinkResponse = await fetch('https://tmpfile.link/api/upload', { method: 'POST', body: formData }); const tfLinkData = await tfLinkResponse.json(); // Generate one-time token const token = uuidv4(); tokenStore.set(token, { downloadLink: tfLinkData.downloadLink, fileName: tfLinkData.fileName, createdAt: new Date(), expiresAt: new Date(Date.now() + 24 * 60 * 60 * 1000) // 24 hours }); res.json({ oneTimeLink: `https://yourapp.com/download/${token}`, expiresAt: tokenStore.get(token).expiresAt }); } catch (error) { res.status(500).json({ error: 'Upload failed' }); } }); // One-time download endpoint app.get('/download/:token', async (req, res) => { const { token } = req.params; const tokenData = tokenStore.get(token); if (!tokenData) { return res.status(410).json({ error: 'Link expired or already used' }); } if (new Date() > tokenData.expiresAt) { tokenStore.delete(token); return res.status(410).json({ error: 'Link expired' }); } // Immediately delete token to ensure one-time use tokenStore.delete(token); // Redirect to actual file res.redirect(tokenData.downloadLink); }); app.listen(3000, () => { console.log('One-time link service running on port 3000'); }); ``` -------------------------------- ### POST /api/v1/upload Source: https://tmpfile.link/blog/api-temp-backup Upload a file to the temporary file service. The API returns a download URL for the uploaded file. ```APIDOC ## POST /api/v1/upload ### Description Upload a file to the temporary file service. The API returns a download URL for the uploaded file. ### Method POST ### Endpoint /api/v1/upload ### Parameters #### Query Parameters - **expires_in** (integer) - Optional - The duration in seconds for which the file will be available. Defaults to 86400 (24 hours). #### Request Body - **file** (file) - Required - The file to upload. - **expires_in** (integer) - Optional - The duration in seconds for which the file will be available. Overrides query parameter if both are present. ### Request Example ```json // JavaScript fetch example async function uploadFile(file, apiKey) { const formData = new FormData(); formData.append('file', file); formData.append('expires_in', '7200'); // 2 hours try { const response = await fetch('/api/v1/upload', { method: 'POST', headers: { 'Authorization': `Bearer ${apiKey}` }, body: formData }); if (!response.ok) { throw new Error(`Upload failed: ${response.status}`); } const result = await response.json(); return result.data.download_url; } catch (error) { console.error('Upload error:', error); throw error; } } // Python requests example import requests import os def upload_temporary_file(file_path, api_key, expires_in=86400): """Upload file and return temporary download link""" url = "https://api.example.com/v1/upload" headers = { "Authorization": f"Bearer {api_key}" } with open(file_path, 'rb') as file: files = {"file": file} data = {"expires_in": expires_in} response = requests.post(url, headers=headers, files=files, data=data) if response.status_code == 200: result = response.json() return result["data"]["download_url"] else: raise Exception(f"Upload failed: {response.text}") ``` ### Response #### Success Response (200) - **success** (boolean) - Indicates if the operation was successful. - **data** (object) - Contains the details of the uploaded file. - **id** (string) - Unique identifier for the file. - **download_url** (string) - The URL to download the file. - **expires_at** (string) - The timestamp when the file will expire (ISO 8601 format). - **file_size** (integer) - The size of the file in bytes. - **content_type** (string) - The MIME type of the file. #### Response Example ```json { "success": true, "data": { "id": "abc123def456", "download_url": "https://tmpfile.link/d/abc123def456", "expires_at": "2024-12-09T10:30:00Z", "file_size": 1024576, "content_type": "application/pdf" } } ``` #### Error Response (e.g., 400, 413, 401, 503) - **success** (boolean) - Indicates if the operation was successful. - **error** (object) - Contains error details. - **code** (string) - An error code (e.g., FILE_TOO_LARGE, INVALID_FILE_TYPE, AUTHENTICATION_FAILED). - **message** (string) - A human-readable error message. - **details** (object) - Optional - Additional details about the error. #### Error Response Example ```json { "success": false, "error": { "code": "FILE_TOO_LARGE", "message": "File size exceeds 100MB limit", "details": { "max_size": 104857600, "received_size": 157286400 } } } ``` ```