当前位置:网站首页>.net upload files through boundary
.net upload files through boundary
2022-07-28 04:01:00 【SingYi】
public void UploadVedio(string fileName)
{
fileName = "input_video_only_3sec.mp4";
byte[] vedioBytes = null;
using (FileStream fileStream = new FileStream(@"D:\ Cache content \test.mp4", FileMode.Open, FileAccess.Read))
{
try
{
vedioBytes = new byte[fileStream.Length];
fileStream.Read(vedioBytes, 0, (int)fileStream.Length);
}
catch (Exception ex)
{
throw ex;
}
}
string cookie = "";
string token = getUploadToken(cookie);
string boundary = "------WebKitFormBoundary5TsAeTVHbPVlsrNh";
string newline = "\r\n";
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(new Uri(""));
req.ContentType = $"multipart/form-data;boundary=----WebKitFormBoundary5TsAeTVHbPVlsrNh";
req.Headers.Add("Authorization", token);
byte[] itemBoundaryBytes = Encoding.UTF8.GetBytes("\r\n" + boundary + "\r\n");
byte[] endBoundaryBytes = Encoding.UTF8.GetBytes("\r\n" + boundary + "--\r\n");
req.Method = "POST";
Stream reqStream = req.GetRequestStream();
string textTemplate = $"Content-Disposition: form-data; name=\"name\"" + newline;
textTemplate += newline;
textTemplate += fileName + newline;
textTemplate += boundary + newline;
textTemplate += $"Content-Disposition: form-data; name=\"size\"" + newline;
textTemplate += newline;
textTemplate += vedioBytes.Length + newline;
textTemplate += boundary + newline;
textTemplate += $"Content-Disposition: form-data; name=\"dir\"" + newline;
textTemplate += newline + newline;
textTemplate += boundary + newline;
byte[] itemBytes = Encoding.UTF8.GetBytes(textTemplate);
reqStream.Write(itemBoundaryBytes, 0, itemBoundaryBytes.Length);
reqStream.Write(itemBytes, 0, itemBytes.Length);
string fileTemplate = $"Content-Disposition: form-data; name=\"file\"; filename=\"{fileName}\"\r\nContent-Type: video/mp4" + newline + newline;
byte[] fileBytes = Encoding.UTF8.GetBytes(fileTemplate);
reqStream.Write(fileBytes, 0, fileBytes.Length);
reqStream.Write(vedioBytes, 0, vedioBytes.Length);
reqStream.Write(endBoundaryBytes, 0, endBoundaryBytes.Length);
reqStream.Close();
reqStream.Dispose();
HttpWebResponse rsp = (HttpWebResponse)req.GetResponse();
Encoding encoding = Encoding.UTF8;
if (!string.IsNullOrEmpty(rsp.CharacterSet))
{
encoding = Encoding.GetEncoding(rsp.CharacterSet);
}
}One more Python Version of :
headers = {'Authorization': token, 'Content-Type': 'multipart/form-data;boundary=-------28947758029299'}
url = ''
fileContent = await file.read()
multipart_encoder = MultipartEncoder(
fields={'name': file.filename, 'size': str(len(fileContent)),
'file': (file.filename, fileContent, 'video/mp4')}, boundary='-------28947758029299')
headers['Content-Type'] = multipart_encoder.content_type
return requests.post(url=url, headers=headers, data=multipart_encoder, verify=False).json()边栏推荐
- [untitled]
- Monotonic stack - 739. Daily temperature
- CH340 RTS DTR引脚编程驱动OLED
- [prototype and prototype chain] get to know prototype and prototype chain~
- Linux - MySQL advanced (day19)
- 企业数字化建设“三不五要”原则
- 基于SSM实现在线租房系统
- Adding DSP library to STM32F103 and its solution
- LeetCode_409_最长回文串
- Advanced Mathematics (Seventh Edition) Tongji University exercises 3-4 personal solutions (first 8 questions)
猜你喜欢

Common interface testing tools

numeric_ Limits the range and related attributes of each data type learned

Interface automation test, complete introduction

Summary and interpretation of CONDA virtual environment

一文读懂Plato Farm的ePLATO,以及其高溢价缘由

Read Plato farm's eplato and the reason for its high premium

How does MySQL ensure high availability

CV2. Threshold(), CV2. Findcontours(), CV2. Findcontours image contour processing
![[prototype and prototype chain] get to know prototype and prototype chain~](/img/8a/d6362fdd50dc883ff817a997ab9e1e.png)
[prototype and prototype chain] get to know prototype and prototype chain~

数据丰富的计算:M.2在边缘遇到AI
随机推荐
Convert py file to exe executable file
程序人生 | 测试工程师还只会点点点?7个捷径教给你快速学习新技术...
In depth introduction to sap ui5 fileuploader control - why do you need a hidden iframe trial
[leetcode] 34. Find the first and last positions of elements in the sorted array
[Luogu p4590] garden party (DP set DP)
Leetcode 0141. circular linked list - three solutions
数据丰富的计算:M.2在边缘遇到AI
WordPress simple mkblog blog theme template v2.1
Monotonous stack -- 42. Receiving rain -- a difficult problem that big factories must know
Qt:qmessagebox message box, custom signal and slot
搬家通知!
Detailed explanation of string + memory function (C language)
In the official online CV2 document, check the optional values of OpenCV specific parameters
Summary and interpretation of CONDA virtual environment
Common interface testing tools
Selenium -- Web automated testing tool
《剑指offer》| 刷题小记
月薪28K学员 自动化测试经验分享
Protocols in swift
LeetCode 0140. 单词拆分 II