{"id":3098,"date":"2023-07-26T09:03:08","date_gmt":"2023-07-26T09:03:08","guid":{"rendered":"https:\/\/www.2ba.nl\/?p=3098"},"modified":"2023-10-27T10:30:48","modified_gmt":"2023-10-27T10:30:48","slug":"via-deliveryupload-api","status":"publish","type":"post","link":"https:\/\/2ba.wimwillems.nl\/en\/documentation\/file-exchange\/file-upload\/via-deliveryupload-api\/","title":{"rendered":"Via API"},"content":{"rendered":"\n<h1 class=\"wp-block-heading\">DeliveryUpload UploadFile (Streaming)<\/h1>\n\n\n\n<h3 class=\"wp-block-heading\">Description<\/h3>\n\n\n\n<p>Upload a catalog file to the 2BA database.<br>Please refer to our <a href=\"\/documentatie\/webservices\/introductie-webservices\">Webservices documentation<\/a> how to use this upload function regarding access and security.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Resource URL<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">json: https:\/\/api.2ba.nl\/1\/streaming\/DeliveryUpload\/UploadFile\n\nThe input is a MultipartFormDataContent with the parameter:<\/pre>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>&nbsp;<strong><strong>file<\/strong><\/strong>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>required<\/p>\n<\/td><td>&nbsp;Stream with file. This file should be one of the accepted formats (<a href=\"\/documentation\/file-exchange\/file-formats\/overview-fileformats\">bestandsformaten<\/a>) compressed using zip, 7z or gzip. The maximum filesize is 2GB. For larger files see our alternative upload through <a href=\"documentatie\/bestandsuitwisseling\/upload-bestanden\/via-sftp\">SFTP<\/a><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Response Object<\/h3>\n\n\n\n<p>The UploadFile service returns the normale HTTP Status as response.<\/p>\n\n\n\n<p>c# sample code<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\n       public async Task Upload(byte&#x5B;] file, string filename)\n        {\n            string result;\n            if (string.IsNullOrEmpty(_refreshToken))\n            {\n                \/\/ Only once during the application life time the GetTokenResourceOwnerPasswordCredentials is called\n                await GetTokens();\n            }\n            if (_client == null) {\n                \/\/ The HttpClient object is intended to live for as long as this application needs to make HTTP requests.\n                InitializeClient();\n            }\n\n            var uri = new Uri(_baseUri, &quot;Streaming\/DeliveryUpload\/UploadFile&quot;);\n\n            using (var content = new MultipartFormDataContent())\n            {\n                \/\/ Add parameter process. Process file after upload?\n                content.Add(new StringContent(((int)_settings.ProcessFile).ToString()), &quot;process&quot;);\n                \n                \/\/ Add file as stream\n                content.Add(new StreamContent(new MemoryStream(file)), filename, filename);\n\n                try\n                {\n                    result = await PostFile(uri, content);\n\n                    if (string.IsNullOrEmpty(result))\n                    {\n                        \/\/ Tokens refreshed. Retry once!\n                        result = await PostFile(uri, content);\n                        if (string.IsNullOrEmpty(result))\n                        {\n                            throw new FileWatchUploadException($&quot;Retry upload failed. Stop retrying.&quot;);              \n                        }\n                    }\n                }\n                catch (TaskCanceledException ex)\n                {\n                    \/\/ Check ex.CancellationToken.IsCancellationRequested here.\n                    \/\/ If false, it&#039;s pretty safe to assume it was a timeout.\n                    if (ex.CancellationToken.IsCancellationRequested)\n                    {\n                        _logger.LogError($&quot;Problem uploading file *** Timeout ***&quot;);\n                    }\n                    throw;\n                }\n                catch (Exception e)\n                {\n                    throw new FileWatchUploadException($&quot;Problem uploading file to { _settings.RestServiceUrl }&quot;, e);\n                }\n            }\n\n            return JsonConvert.DeserializeObject(result);\n        }\n\n        private void InitializeClient()\n        {\n            _client = new HttpClient();\n            _client.MaxResponseContentBufferSize = 256000;\n            _client.Timeout = TimeSpan.FromMinutes(30);\n            _client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(&quot;Bearer&quot;, _accessToken);\n        }\n\n        private async Task PostFile(Uri uri, MultipartFormDataContent content)\n        {\n            var result = string.Empty;\n\n            using (var response = await _client.PostAsync(uri, content))\n            {\n                if (response.IsSuccessStatusCode)\n                {\n                    \/\/ return result\n                    _logger.LogInformation(&quot;Upload OK: &quot; + _baseUri);\n                    result = await response.Content.ReadAsStringAsync();\n                    return result;\n                }\n                else if (response.StatusCode == HttpStatusCode.Unauthorized)\n                {\n                    \/\/ return empty result\n                    _logger.LogInformation($&quot;Unauthorized at: { _baseUri }. Start refreshing tokens&quot;);\n                    var tokens = await _authorizeServices.RefreshToken(_refreshToken);\n                    _client.DefaultRequestHeaders.Remove(&quot;Bearer&quot;);\n                    _client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(&quot;Bearer&quot;, tokens.access_token);\n                    return result;\n                }\n                else\n                {\n                    \/\/ throw exception\n                    throw new FileWatchUploadException($&quot;Error uploading file. Statuscode: {response.StatusCode }. {response.ReasonPhrase} \\n {uri}&quot;);\n                }\n            }\n        }\n\n        private async Task GetTokens()\n        {\n            try\n            {\n                var tokenResponse = await _authorizeServices.GetTokenResourceOwnerPasswordCredentials();\n                _refreshToken = tokenResponse.refresh_token;\n                _accessToken = tokenResponse.access_token;\n            }\n            catch (Exception)\n            {\n                _logger.LogError($&quot;Unable to get tokens at { _settings.AuthServiceUrl }&quot;);\n                throw;\n            }\n        }\n    }\n&lt;\/string&gt;&lt;\/importfilelist&gt;&lt;\/importfilelist&gt;\n<\/pre><\/div>","protected":false},"excerpt":{"rendered":"<p>DeliveryUpload UploadFile (Streaming) Description Upload a catalog file to the 2BA database.Please refer to our Webservices documentation how to use this upload function regarding access and security. Resource URL json: https:\/\/api.2ba.nl\/1\/streaming\/DeliveryUpload\/UploadFile The input is a MultipartFormDataContent with the parameter: &nbsp;file &nbsp; &nbsp; required &nbsp;Stream with file. This file should be one of the accepted formats [&hellip;]<\/p>\n","protected":false},"author":11,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_uag_custom_page_level_css":"","footnotes":""},"categories":[125],"tags":[],"class_list":["post-3098","post","type-post","status-publish","format-standard","hentry","category-file-upload"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.2 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Via API - 2ba<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/2ba.wimwillems.nl\/documentatie\/bestandsuitwisseling\/upload-bestanden\/via-deliveryupload-api\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Via API - 2ba\" \/>\n<meta property=\"og:description\" content=\"DeliveryUpload UploadFile (Streaming) Description Upload a catalog file to the 2BA database.Please refer to our Webservices documentation how to use this upload function regarding access and security. Resource URL json: https:\/\/api.2ba.nl\/1\/streaming\/DeliveryUpload\/UploadFile The input is a MultipartFormDataContent with the parameter: &nbsp;file &nbsp; &nbsp; required &nbsp;Stream with file. This file should be one of the accepted formats [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/2ba.wimwillems.nl\/documentatie\/bestandsuitwisseling\/upload-bestanden\/via-deliveryupload-api\/\" \/>\n<meta property=\"og:site_name\" content=\"2ba\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-26T09:03:08+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-10-27T10:30:48+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/2ba.wimwillems.nl\/wp-content\/uploads\/2023\/06\/2BA_logo_RGB.png\" \/>\n\t<meta property=\"og:image:width\" content=\"211\" \/>\n\t<meta property=\"og:image:height\" content=\"95\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"2ba\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"2ba\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/2ba.wimwillems.nl\/documentatie\/bestandsuitwisseling\/upload-bestanden\/via-deliveryupload-api\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/2ba.wimwillems.nl\/documentatie\/bestandsuitwisseling\/upload-bestanden\/via-deliveryupload-api\/\"},\"author\":{\"name\":\"2ba\",\"@id\":\"https:\/\/2ba.wimwillems.nl\/#\/schema\/person\/e38a7da4ab5c525bc5ff65c2f9f29412\"},\"headline\":\"Via API\",\"datePublished\":\"2023-07-26T09:03:08+00:00\",\"dateModified\":\"2023-10-27T10:30:48+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/2ba.wimwillems.nl\/documentatie\/bestandsuitwisseling\/upload-bestanden\/via-deliveryupload-api\/\"},\"wordCount\":86,\"commentCount\":0,\"articleSection\":[\"File upload\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/2ba.wimwillems.nl\/documentatie\/bestandsuitwisseling\/upload-bestanden\/via-deliveryupload-api\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/2ba.wimwillems.nl\/documentatie\/bestandsuitwisseling\/upload-bestanden\/via-deliveryupload-api\/\",\"url\":\"https:\/\/2ba.wimwillems.nl\/documentatie\/bestandsuitwisseling\/upload-bestanden\/via-deliveryupload-api\/\",\"name\":\"Via API - 2ba\",\"isPartOf\":{\"@id\":\"https:\/\/2ba.wimwillems.nl\/#website\"},\"datePublished\":\"2023-07-26T09:03:08+00:00\",\"dateModified\":\"2023-10-27T10:30:48+00:00\",\"author\":{\"@id\":\"https:\/\/2ba.wimwillems.nl\/#\/schema\/person\/e38a7da4ab5c525bc5ff65c2f9f29412\"},\"breadcrumb\":{\"@id\":\"https:\/\/2ba.wimwillems.nl\/documentatie\/bestandsuitwisseling\/upload-bestanden\/via-deliveryupload-api\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/2ba.wimwillems.nl\/documentatie\/bestandsuitwisseling\/upload-bestanden\/via-deliveryupload-api\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/2ba.wimwillems.nl\/documentatie\/bestandsuitwisseling\/upload-bestanden\/via-deliveryupload-api\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/2ba.wimwillems.nl\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Via API\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/2ba.wimwillems.nl\/#website\",\"url\":\"https:\/\/2ba.wimwillems.nl\/\",\"name\":\"2ba\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/2ba.wimwillems.nl\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/2ba.wimwillems.nl\/#\/schema\/person\/e38a7da4ab5c525bc5ff65c2f9f29412\",\"name\":\"2ba\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/secure.gravatar.com\/avatar\/98fd787799f599e7136207ddae02d3ff6c5d346317929a6e3bac964389f20320?s=96&d=mm&r=g\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/98fd787799f599e7136207ddae02d3ff6c5d346317929a6e3bac964389f20320?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/98fd787799f599e7136207ddae02d3ff6c5d346317929a6e3bac964389f20320?s=96&d=mm&r=g\",\"caption\":\"2ba\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Via API - 2ba","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/2ba.wimwillems.nl\/documentatie\/bestandsuitwisseling\/upload-bestanden\/via-deliveryupload-api\/","og_locale":"en_US","og_type":"article","og_title":"Via API - 2ba","og_description":"DeliveryUpload UploadFile (Streaming) Description Upload a catalog file to the 2BA database.Please refer to our Webservices documentation how to use this upload function regarding access and security. Resource URL json: https:\/\/api.2ba.nl\/1\/streaming\/DeliveryUpload\/UploadFile The input is a MultipartFormDataContent with the parameter: &nbsp;file &nbsp; &nbsp; required &nbsp;Stream with file. This file should be one of the accepted formats [&hellip;]","og_url":"https:\/\/2ba.wimwillems.nl\/documentatie\/bestandsuitwisseling\/upload-bestanden\/via-deliveryupload-api\/","og_site_name":"2ba","article_published_time":"2023-07-26T09:03:08+00:00","article_modified_time":"2023-10-27T10:30:48+00:00","og_image":[{"width":211,"height":95,"url":"https:\/\/2ba.wimwillems.nl\/wp-content\/uploads\/2023\/06\/2BA_logo_RGB.png","type":"image\/png"}],"author":"2ba","twitter_card":"summary_large_image","twitter_misc":{"Written by":"2ba","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/2ba.wimwillems.nl\/documentatie\/bestandsuitwisseling\/upload-bestanden\/via-deliveryupload-api\/#article","isPartOf":{"@id":"https:\/\/2ba.wimwillems.nl\/documentatie\/bestandsuitwisseling\/upload-bestanden\/via-deliveryupload-api\/"},"author":{"name":"2ba","@id":"https:\/\/2ba.wimwillems.nl\/#\/schema\/person\/e38a7da4ab5c525bc5ff65c2f9f29412"},"headline":"Via API","datePublished":"2023-07-26T09:03:08+00:00","dateModified":"2023-10-27T10:30:48+00:00","mainEntityOfPage":{"@id":"https:\/\/2ba.wimwillems.nl\/documentatie\/bestandsuitwisseling\/upload-bestanden\/via-deliveryupload-api\/"},"wordCount":86,"commentCount":0,"articleSection":["File upload"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/2ba.wimwillems.nl\/documentatie\/bestandsuitwisseling\/upload-bestanden\/via-deliveryupload-api\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/2ba.wimwillems.nl\/documentatie\/bestandsuitwisseling\/upload-bestanden\/via-deliveryupload-api\/","url":"https:\/\/2ba.wimwillems.nl\/documentatie\/bestandsuitwisseling\/upload-bestanden\/via-deliveryupload-api\/","name":"Via API - 2ba","isPartOf":{"@id":"https:\/\/2ba.wimwillems.nl\/#website"},"datePublished":"2023-07-26T09:03:08+00:00","dateModified":"2023-10-27T10:30:48+00:00","author":{"@id":"https:\/\/2ba.wimwillems.nl\/#\/schema\/person\/e38a7da4ab5c525bc5ff65c2f9f29412"},"breadcrumb":{"@id":"https:\/\/2ba.wimwillems.nl\/documentatie\/bestandsuitwisseling\/upload-bestanden\/via-deliveryupload-api\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/2ba.wimwillems.nl\/documentatie\/bestandsuitwisseling\/upload-bestanden\/via-deliveryupload-api\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/2ba.wimwillems.nl\/documentatie\/bestandsuitwisseling\/upload-bestanden\/via-deliveryupload-api\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/2ba.wimwillems.nl\/en\/"},{"@type":"ListItem","position":2,"name":"Via API"}]},{"@type":"WebSite","@id":"https:\/\/2ba.wimwillems.nl\/#website","url":"https:\/\/2ba.wimwillems.nl\/","name":"2ba","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/2ba.wimwillems.nl\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/2ba.wimwillems.nl\/#\/schema\/person\/e38a7da4ab5c525bc5ff65c2f9f29412","name":"2ba","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/98fd787799f599e7136207ddae02d3ff6c5d346317929a6e3bac964389f20320?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/98fd787799f599e7136207ddae02d3ff6c5d346317929a6e3bac964389f20320?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/98fd787799f599e7136207ddae02d3ff6c5d346317929a6e3bac964389f20320?s=96&d=mm&r=g","caption":"2ba"}}]}},"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false,"gform-image-choice-sm":false,"gform-image-choice-md":false,"gform-image-choice-lg":false},"uagb_author_info":{"display_name":"2ba","author_link":"https:\/\/2ba.wimwillems.nl\/en\/author\/2ba\/"},"uagb_comment_info":0,"uagb_excerpt":"DeliveryUpload UploadFile (Streaming) Description Upload a catalog file to the 2BA database.Please refer to our Webservices documentation how to use this upload function regarding access and security. Resource URL json: https:\/\/api.2ba.nl\/1\/streaming\/DeliveryUpload\/UploadFile The input is a MultipartFormDataContent with the parameter: &nbsp;file &nbsp; &nbsp; required &nbsp;Stream with file. This file should be one of the accepted formats&hellip;","_links":{"self":[{"href":"https:\/\/2ba.wimwillems.nl\/en\/wp-json\/wp\/v2\/posts\/3098","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/2ba.wimwillems.nl\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/2ba.wimwillems.nl\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/2ba.wimwillems.nl\/en\/wp-json\/wp\/v2\/users\/11"}],"replies":[{"embeddable":true,"href":"https:\/\/2ba.wimwillems.nl\/en\/wp-json\/wp\/v2\/comments?post=3098"}],"version-history":[{"count":3,"href":"https:\/\/2ba.wimwillems.nl\/en\/wp-json\/wp\/v2\/posts\/3098\/revisions"}],"predecessor-version":[{"id":4599,"href":"https:\/\/2ba.wimwillems.nl\/en\/wp-json\/wp\/v2\/posts\/3098\/revisions\/4599"}],"wp:attachment":[{"href":"https:\/\/2ba.wimwillems.nl\/en\/wp-json\/wp\/v2\/media?parent=3098"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/2ba.wimwillems.nl\/en\/wp-json\/wp\/v2\/categories?post=3098"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/2ba.wimwillems.nl\/en\/wp-json\/wp\/v2\/tags?post=3098"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}