|  | 
|  | 1 | +# OneDrive Upload API | 
|  | 2 | + | 
|  | 3 | +A serverless API service for uploading files to OneDrive with support for multiple remote configurations. | 
|  | 4 | + | 
|  | 5 | +## API Endpoint | 
|  | 6 | + | 
|  | 7 | +### POST /upload | 
|  | 8 | + | 
|  | 9 | +Upload a file to OneDrive. | 
|  | 10 | + | 
|  | 11 | +**Request Format:** | 
|  | 12 | +- Content-Type: `multipart/form-data` | 
|  | 13 | + | 
|  | 14 | +**Form Fields:** | 
|  | 15 | +- `file`: (required) The file to upload | 
|  | 16 | +- `remote`: (required) Remote configuration to use (`hakimionedrive`, `oned`, or `saurajcf`) | 
|  | 17 | +- `remoteFolder`: (optional) Folder path in OneDrive where the file should be uploaded | 
|  | 18 | +- `remoteFileName`: (optional) Custom name for the uploaded file | 
|  | 19 | +- `chunkSize`: (required) Upload chunk size in MB (2, 4, 8, or 16) | 
|  | 20 | + | 
|  | 21 | +**Success Response:** | 
|  | 22 | +```json | 
|  | 23 | +{ | 
|  | 24 | +    "status": "success", | 
|  | 25 | +    "message": "File uploaded successfully", | 
|  | 26 | +    "downloadURL": "https://your-index.vercel.app/path/to/file", | 
|  | 27 | +    "fileSize": 1234567, | 
|  | 28 | +    "fileName": "example.pdf" | 
|  | 29 | +} | 
|  | 30 | +``` | 
|  | 31 | + | 
|  | 32 | +**Error Response:** | 
|  | 33 | +```json | 
|  | 34 | +{ | 
|  | 35 | +    "error": "Error message here", | 
|  | 36 | +    "details": "Detailed error information" | 
|  | 37 | +} | 
|  | 38 | +``` | 
|  | 39 | + | 
|  | 40 | +## Deployment | 
|  | 41 | + | 
|  | 42 | +### Prerequisites | 
|  | 43 | +1. OneDrive API credentials in rclone.conf | 
|  | 44 | +2. Vercel account and Vercel CLI installed | 
|  | 45 | + | 
|  | 46 | +### Deploy to Vercel | 
|  | 47 | + | 
|  | 48 | +1. Clone this repository | 
|  | 49 | +```bash | 
|  | 50 | +git clone https://github.com/ksauraj/ksau-oned-api.git | 
|  | 51 | +cd ksau-oned-api | 
|  | 52 | +``` | 
|  | 53 | + | 
|  | 54 | +2. Add your rclone.conf file to the project root | 
|  | 55 | + | 
|  | 56 | +3. Deploy to Vercel | 
|  | 57 | +```bash | 
|  | 58 | +vercel | 
|  | 59 | +``` | 
|  | 60 | + | 
|  | 61 | +### Local Development | 
|  | 62 | + | 
|  | 63 | +1. Clone the repository and add your rclone.conf file | 
|  | 64 | + | 
|  | 65 | +2. Start the development server | 
|  | 66 | +```bash | 
|  | 67 | +go run main.go | 
|  | 68 | +``` | 
|  | 69 | + | 
|  | 70 | +The server will start on http://localhost:8080 with the following endpoint: | 
|  | 71 | +- Upload endpoint: http://localhost:8080/upload | 
|  | 72 | + | 
|  | 73 | +## Configuration | 
|  | 74 | + | 
|  | 75 | +The API supports multiple OneDrive remotes which are configured in the code: | 
|  | 76 | + | 
|  | 77 | +```go | 
|  | 78 | +var rootFolders = map[string]string{ | 
|  | 79 | +    "hakimionedrive": "Public", | 
|  | 80 | +    "oned":           "", | 
|  | 81 | +    "saurajcf":       "MY_BOMT_STUFFS", | 
|  | 82 | +} | 
|  | 83 | + | 
|  | 84 | +var baseURLs = map[string]string{ | 
|  | 85 | +    "hakimionedrive": "https://onedrive-vercel-index-kohl-eight-30.vercel.app", | 
|  | 86 | +    "oned":           "https://index.sauraj.eu.org", | 
|  | 87 | +    "saurajcf":       "https://my-index-azure.vercel.app", | 
|  | 88 | +} | 
|  | 89 | +``` | 
|  | 90 | + | 
|  | 91 | +## Error Handling and Logging | 
|  | 92 | + | 
|  | 93 | +The API includes comprehensive error handling and logging: | 
|  | 94 | +- Request validation with detailed error messages | 
|  | 95 | +- File size and type validation | 
|  | 96 | +- Detailed logging of upload process | 
|  | 97 | +- Proper cleanup of temporary files | 
|  | 98 | +- Memory limits to prevent server overload | 
|  | 99 | + | 
|  | 100 | +## Security | 
|  | 101 | + | 
|  | 102 | +- The API uses CORS headers to allow requests from any origin | 
|  | 103 | +- Request size limits and validations are in place | 
|  | 104 | +- Proper cleanup of temporary files | 
|  | 105 | +- Keep your rclone.conf secure and never commit it to version control | 
|  | 106 | + | 
|  | 107 | +## License | 
|  | 108 | + | 
|  | 109 | +See [LICENSE](LICENSE) file for details. | 
0 commit comments