umasankar umasankar - 28 days ago 8
reST (reStructuredText) Question

How to Solve Azure DataLakeStore File Content-Disposition Added in file?

I was Uploaded Text file or image file or Zip File to Azure Data Lake Store. it' was Uploaded Successfully. But, before added some content in file.
I was Uploaded a File using Rest API. (Uploaded file using HttpClient in C#)

this Type of Content Added in


---b8b2dfc6-6128-43b5-8fb8-022820aedf02

Content-Disposition: form-data;
name=file1; filename=tick.txt; filename*=utf-8''tick.txt


If the Content Added So, The Image file and zip files are Not Open in Viewer/Explore.

How To Remove this type of header added in file From Upload.Here I shared my file uploaded code.

public object UploadFile(string srcfile, string destFilePath, bool force = true)
{
var uploadurl = string.Format(UploadUrl, _datalakeAccountName, destFilePath);
var stream = File.OpenRead(srcfile);
HttpContent fileStreamContent = new StreamContent(stream);
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", _accesstoken.access_token);
using (var formData = new MultipartFormDataContent())
{
formData.Add(fileStreamContent, "file1", Path.GetFileName(srcfile));
var response = client.PutAsync(uploadurl, formData).Result;
return new { Status = response.StatusCode, Message = response.ReasonPhrase, details = response.ToString() };
}
}
}


Thanks in Advance.

Answer Source

Please have try to use the following code, it works correcly on my side.

 public object UploadFile(string srcfile, string destFilePath, bool force = true)
    {
        var uploadurl = string.Format(UploadUrl, _datalakeAccountName, destFilePath);
        var stream = File.OpenRead(srcfile);
        HttpContent fileStreamContent = new StreamContent(stream);
        using (var client = new HttpClient())
        {
            client.DefaultRequestHeaders.Authorization = new
                AuthenticationHeaderValue("Bearer",  _accesstoken.access_token);
            client.DefaultRequestHeaders
                .Accept
                .Add(new MediaTypeWithQualityHeaderValue("application/octet-stream"));
            var response = client.PutAsync(uploadurl, fileStreamContent).Result;

            return new { Status = response.StatusCode, Message = response.ReasonPhrase, details = response.ToString() };
        }
    }