gpt-3.5-turbo-0301· OpenAI
WildChat-4.8M (AI2)
net core 上传文件夹
- User
net core 上传文件夹
- Assistant
在 .NET Core 中,你可以使用
System.IO命名空间中的类来上传文件夹。以下是一个示例代码:using System.IO; using Microsoft.AspNetCore.Http; public async Task UploadDirectory(IFormFile folder, string targetPath) { if (folder.Length > 0) { // 创建目标文件夹 Directory.CreateDirectory(targetPath); // 遍历上传文件夹并上传每个文件 using (var stream = new MemoryStream()) { await folder.CopyToAsync(stream); stream.Position = 0; using (var archive = new ZipArchive(stream)) { foreach (var entry in archive.Entries) { if (entry.Length > 0) { var entryTargetPath = Path.Combine(targetPath, entry.FullName); // 创建文件夹 Directory.CreateDirectory(Path.GetDirectoryName(entryTargetPath)); // 写入文件 using (var entryStream = entry.Open()) using (var fileStream = new FileStream(entryTargetPath, FileMode.Create)) { await entryStream.CopyToAsync(fileStream); } } } } } } }
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.