{"id":20970453,"url":"https://github.com/crossgeeks/fileuploaderplugin","last_synced_at":"2025-04-13T08:23:19.466Z","repository":{"id":87069388,"uuid":"95404662","full_name":"CrossGeeks/FileUploaderPlugin","owner":"CrossGeeks","description":"Simple cross platform plugin to upload files.","archived":false,"fork":false,"pushed_at":"2020-10-18T11:37:22.000Z","size":2905,"stargazers_count":68,"open_issues_count":21,"forks_count":27,"subscribers_count":13,"default_branch":"master","last_synced_at":"2025-03-27T00:11:11.615Z","etag":null,"topics":["file","multipart","plugin","upload","xamarin"],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/CrossGeeks.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-06-26T03:23:49.000Z","updated_at":"2024-11-23T03:21:05.000Z","dependencies_parsed_at":"2023-06-03T03:30:38.946Z","dependency_job_id":null,"html_url":"https://github.com/CrossGeeks/FileUploaderPlugin","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CrossGeeks%2FFileUploaderPlugin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CrossGeeks%2FFileUploaderPlugin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CrossGeeks%2FFileUploaderPlugin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CrossGeeks%2FFileUploaderPlugin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CrossGeeks","download_url":"https://codeload.github.com/CrossGeeks/FileUploaderPlugin/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248681892,"owners_count":21144762,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["file","multipart","plugin","upload","xamarin"],"created_at":"2024-11-19T03:58:30.626Z","updated_at":"2025-04-13T08:23:19.432Z","avatar_url":"https://github.com/CrossGeeks.png","language":"C#","readme":"## FileUploader Plugin for Xamarin iOS, Android, UWP, Mac, tvOS and watchOS\nSimple cross platform plugin for file multipart uploads.\n\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"https://github.com/CrossGeeks/FileUploaderPlugin/blob/master/FileUploader%20Plugin%20-%20Android.gif\" title=\"Android\"/\u003e\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\n\u003cimg src=\"https://github.com/CrossGeeks/FileUploaderPlugin/blob/master/FileUploader%20Plugin%20-%20iOS.gif\" title=\"iOS\"/\u003e\n\u003c/p\u003e\n\n## Features\n\n- Multipart file uploading with headers and parameters\n- Upload multiple files at once\n- Upload request progress feedback\n- Upload files by using bytes or file path\n- Set custom boundary\n\n### Setup\n* Available on NuGet: http://www.nuget.org/packages/Plugin.FileUploader [![NuGet](https://img.shields.io/nuget/v/Plugin.FileUploader.svg?label=NuGet)](https://www.nuget.org/packages/Plugin.FileUploader/)\n* Install into your PCL project and Client projects.\n\n\n**Platform Support**\n\n|Platform|Version|\n| ------------------- | :------------------: |\n|Xamarin.iOS|iOS 7+|\n|Xamarin.Android|API 15+|\n|Windows 10 UWP|10+|\n|Xamarin.Mac|10.9+|\n|watchOS|2.0+|\n|tvOS|9.0+|\n\n### API Usage\n\nCall **CrossFileUploader.Current** from any project or PCL to gain access to APIs.\n\nYou can upload a file using the file path or bytes.\n\n\n**FilePathItem**\n```csharp\n/// \u003csummary\u003e\n/// Path: File path location.\n/// FieldName: Request field name for the file to be uploaded\n/// \u003c/summary\u003e\npublic class FilePathItem\n{\n    public string Path { get; } \n    public string FieldName {get; } \n}\n```\n\n\n**FileBytesItem**\n```csharp\n/// \u003csummary\u003e\n/// FieldName: Request field name for the file to be uploaded\n/// Bytes: File bytes.\n/// Name: Name of the file.\n/// \u003c/summary\u003e\npublic class FileBytesItem\n{\n    public string Name { get; }\n    public string FieldName { get; }\n    public byte[] Bytes { get; }\n}\n```\n\n\n**UploadFileAsync**\n```csharp\n        /// \u003csummary\u003e\n        /// Upload file using file path\n        /// \u003c/summary\u003e\n        /// \u003cparam name=\"url\"\u003eUrl for file uploading\u003c/param\u003e\n        /// \u003cparam name=\"fileItem\"\u003eFile path item to be uploaded\u003c/param\u003e\n        /// \u003cparam name=\"headers\"\u003eRequest headers\u003c/param\u003e\n        /// \u003cparam name=\"parameters\"\u003eAdditional parameters for upload request\u003c/param\u003e\n        /// \u003cparam name=\"boundary\"\u003eCustom part boundary\u003c/param\u003e\n        /// \u003creturns\u003eFileUploadResponse\u003c/returns\u003e\n        Task\u003cFileUploadResponse\u003e UploadFileAsync(string url, FilePathItem fileItem, IDictionary\u003cstring,string\u003e headers =null,IDictionary \u003c string, string\u003e parameters = null, string boundary = null);\n\n        /// \u003csummary\u003e\n        /// Upload files using file path\n        /// \u003c/summary\u003e\n        /// \u003cparam name=\"url\"\u003eUrl for file uploading\u003c/param\u003e\n        /// \u003cparam name=\"fileItems\"\u003eFile path items to be uploaded\u003c/param\u003e\n        /// \u003cparam name=\"tag\"\u003eTag reference of the upload request\u003c/param\u003e\n        /// \u003cparam name=\"headers\"\u003eRequest headers\u003c/param\u003e\n        /// \u003cparam name=\"parameters\"\u003eAdditional parameters for upload request\u003c/param\u003e\n        /// \u003cparam name=\"boundary\"\u003eCustom part boundary\u003c/param\u003e\n        /// \u003creturns\u003eFileUploadResponse\u003c/returns\u003e\n        Task\u003cFileUploadResponse\u003e UploadFileAsync(string url, FilePathItem[] fileItems,string tag, IDictionary\u003cstring, string\u003e headers = null, IDictionary\u003cstring, string\u003e parameters = null, string boundary = null);\n\n        /// \u003csummary\u003e\n        /// Upload file using file bytes\n        /// \u003c/summary\u003e\n        /// \u003cparam name=\"url\"\u003eUrl for file uploading\u003c/param\u003e\n        /// \u003cparam name=\"fileItem\"\u003eFile bytes item to be uploaded\u003c/param\u003e\n        /// \u003cparam name=\"headers\"\u003eRequest headers\u003c/param\u003e\n        /// \u003cparam name=\"parameters\"\u003eAdditional parameters for upload request\u003c/param\u003e\n        /// \u003cparam name=\"boundary\"\u003eCustom part boundary\u003c/param\u003e\n        /// \u003creturns\u003eFileUploadResponse\u003c/returns\u003e\n        Task\u003cFileUploadResponse\u003e UploadFileAsync(string url, FileBytesItem fileItem, IDictionary\u003cstring, string\u003e headers = null, IDictionary\u003cstring, string\u003e parameters = null, string boundary = null);\n\n\n        /// \u003csummary\u003e\n        /// Upload files using file bytes\n        /// \u003c/summary\u003e\n        /// \u003cparam name=\"url\"\u003eUrl for file uploading\u003c/param\u003e\n        /// \u003cparam name=\"fileItems\"\u003eFile bytes of items to be uploaded\u003c/param\u003e\n        /// \u003cparam name=\"tag\"\u003eTag reference of upload request\u003c/param\u003e\n        /// \u003cparam name=\"headers\"\u003eRequest headers\u003c/param\u003e\n        /// \u003cparam name=\"parameters\"\u003eAdditional parameters for upload request\u003c/param\u003e\n        /// \u003cparam name=\"boundary\"\u003eCustom part boundary\u003c/param\u003e\n        /// \u003creturns\u003eFileUploadResponse\u003c/returns\u003e\n        Task\u003cFileUploadResponse\u003e UploadFileAsync(string url, FileBytesItem[] fileItems,string tag, IDictionary\u003cstring, string\u003e headers = null, IDictionary\u003cstring, string\u003e parameters = null,string boundary = null);\n```\n\nUsage sample:\n\nUploading from a file path\n```csharp\n\n    CrossFileUploader.Current.UploadFileAsync(\"\u003cURL HERE\u003e\", new FilePathItem(\"\u003cREQUEST FIELD NAME HERE\u003e\",\"\u003cFILE PATH HERE\u003e\"), new Dictionary\u003cstring, string\u003e()\n                {\n                   {\"\u003cHEADER KEY HERE\u003e\" , \"\u003cHEADER VALUE HERE\u003e\"}\n                }\n    );\n\n```\n\nUploading from a file bytes\n```csharp\n\n  CrossFileUploader.Current.UploadFileAsync(\"\u003cURL HERE\u003e\", new FileBytesItem(\"\u003cREQUEST FIELD NAME HERE\u003e\",\"\u003cFILE BYTES HERE\u003e\",\"\u003cFILE NAME HERE\u003e\"), new Dictionary\u003cstring, string\u003e()\n                {\n                   {\"\u003cHEADER KEY HERE\u003e\" , \"\u003cHEADER VALUE HERE\u003e\"}\n                }\n  );\n\n```\nUploading multiple files at once\n```csharp\n\n CrossFileUploader.Current.UploadFileAsync(\"\u003cURL HERE\u003e\", new FilePathItem[]{\n    new FilePathItem(\"file\",path1),\n\tnew FilePathItem(\"file\",path2),\n\tnew FilePathItem(\"file\",path3)\n },\"Upload Tag 1\");\n\n ```\n#### Events in FileUploader\nWhen any file upload completed/failed you can register for an event to fire:\n```csharp\n/// \u003csummary\u003e\n/// Event handler when file is upload completes succesfully\n/// \u003c/summary\u003e\nevent EventHandler\u003cFileUploadResponse\u003e FileUploadCompleted; \n```\n\n```csharp\n/// \u003csummary\u003e\n/// Event handler when file is upload fails\n/// \u003c/summary\u003e\nevent EventHandler\u003cFileUploadResponse\u003e FileUploadError; \n```\n\n```csharp\n /// \u003csummary\u003e\n /// Event handler when file upload is in progress, indicates what's the upload progress so far\n /// \u003c/summary\u003e\n event EventHandler\u003cFileUploadProgress\u003e FileUploadProgress;\n ```\n\nFor events **FileUploadCompleted** and **FileUploadError** you will get a FileUploadResponse with the status and response message:\n\n```csharp\npublic class FileUploadResponse\n{\n        public string Tag { get; }\n        public string Message { get; }\n        public int StatusCode { get; }\n        public IReadOnlyDictionary\u003cstring, string\u003e Headers { get; }\n}\n```\n\nUsage sample:\n```csharp\n\n  CrossFileUploader.Current.FileUploadCompleted += (sender, response) =\u003e\n  {\n    System.Diagnostics.Debug.WriteLine($\"{response.StatusCode} - {response.Message}\");\n  };\n  \n  CrossFileUploader.Current.UploadFileAsync($\"\u003cUPLOAD URL HERE\u003e\",new FileItem(\"\u003cFIELD NAME HERE\u003e\",\"\u003cFILE PATH HERE\u003e\"));\n\n```\n\nWhile upload is in progress you can get feedback on event **FileUploadProgress**\n\nYou will get a FileUploadProgress with the total bytes sent, total request byte length and progress percentage\n\n```csharp\npublic class FileUploadProgress\n{\n        public long TotalBytesSent { get; }\n        public long TotalLength { get; }\n        public double Percentage { get; }\n\tpublic string Tag { get; }\n\n}\n```\n\nUsage sample:\n```csharp\n  CrossFileUploader.Current.FileUploadProgress += (sender, uploadProgress) =\u003e\n  {\n      System.Diagnostics.Debug.WriteLine($\"{uploadProgress.Tag} - {uploadProgress.TotalBytesSent} - {uploadProgress.Percentage}\");\n  };\n```\n### **IMPORTANT**\n\n### iOS:\nOn AppDelegate.cs\n\n```csharp\n    /**\n     * Save the completion-handler we get when the app opens from the background.\n     * This method informs iOS that the app has finished all internal processing and can sleep again.\n     */\n    public override void HandleEventsForBackgroundUrl(UIApplication application, string sessionIdentifier, Action completionHandler)\n    {\n        FileUploadManager.UrlSessionCompletion = completionHandler;\n    }\n```\n\nAlso consider on iOS 9+, your URL must be secured or you have to add the domain to the list of exceptions. See https://github.com/codepath/ios_guides/wiki/App-Transport-Security\n\n### Android:\n\nThere are some android specific static properties to specify timeout information:\n\n```csharp\n        public static TimeUnit UploadTimeoutUnit { get; set; } = TimeUnit.Minutes;\n        public static long SocketUploadTimeout { get; set; } = 5;\n        public static long ConnectUploadTimeout { get; set; } = 5;\n``` \n\nAbove you can see the default values. But you can change the value for the timeouts and unit by setting it from your Android project(Could be on MainActivity) like this:\n\n```csharp\n        FileUploadManager.UploadTimeoutUnit = TimeUnit.Minutes;\n        FileUploadManager.SocketUploadTimeout = 10;\n        FileUploadManager.ConnectUploadTimeout  = 5;\n``` \n\n\n#### Contributors\n\n* [Rendy Del Rosario](https://github.com/rdelrosario)\n* [Charlin Agramonte](https://github.com/char0394)\n* [Angel Andres Mañon](https://github.com/AngelAndresM)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcrossgeeks%2Ffileuploaderplugin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcrossgeeks%2Ffileuploaderplugin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcrossgeeks%2Ffileuploaderplugin/lists"}