英文:
IFormFile without deprecated Microsoft.AspNetCore.Http.Features
问题
我在类库中使用IFormFile
,Microsoft.AspNetCore.Http.Features
已经被弃用。现在在.NET 7中,我需要什么NuGet包,用于IFormFile
?
英文:
I use IFormFile
in class library, Microsoft.AspNetCore.Http.Features
has become deprecated. What kind nugget package I need now, for IFormFile
in .Net 7
答案1
得分: 2
在.NET 7中,IFormFile 已经默认自动集成了。此外,如果您在 流式传输任何文件操作 中使用 IFormFile,则无需安装额外的包,因为 IFormFile 属于 Microsoft.AspNetCore.Http.Features.dll 程序集和 Microsoft.AspNetCore.Http 命名空间已经包含在 .NET 7 中。因此,您不需要安装或包含任何额外的 NuGet 包。
您可以查看以下信息:
如何在类库中使用:
为了在 .NET 7 中在类库中使用 IFormFile,我们可以使用 Microsoft.AspNetCore.Http NuGet 包。虽然它已经超出了支持范围,但仍然可以使用,因为 asp.netcore 2.2 被视为独特的类别并继续保留其传统。
示例:
namespace IFromFileTestClassLibrary
{
public class UploadFiles
{
public async Task<string> FileHandlerMethod(CreateProfileViewModel requestModel)
{
string filePath = "文件保存路径";
var path = Path.Combine(filePath, "Images", requestModel.Photo!.FileName);
if (requestModel.Photo.Length > 0)
{
using var stream = new FileStream(path, FileMode.Create);
await requestModel.Photo.CopyToAsync(stream);
}
return requestModel.ImageURL = path;
}
}
public class CreateProfileViewModel
{
public string? ProfileName { get; set; }
public string? DisplayPhoto { get; set; }
public string? ImageURL { get; set; }
public IFormFile? Photo { get; set; }
}
}
注意: 您可以参考此官方文档获取更多详细信息。
英文:
> I use IFormFile in class library, Microsoft.AspNetCore.Http.Features
> has become deprecated. What kind nugget package I need now, for
> IFormFile in .Net 7
Actually, in .NET 7 IFormFile has been integrated automatically by default. In addition, if you use IFormFile for streaming any file operation you no longer required additional package because IFormFile which is belongs to Microsoft.AspNetCore.Http.Features.dll assembly and Microsoft.AspNetCore.Http namaspace has been included within .Net 7. Thus, you don't need to install or include any additional nuget package for that.
You can have a look at following information:
How To Use In Class Library:
In order to use IFormFile within class library within .NET 7 we can use Microsoft.AspNetCore.Http nuget package. Although its out of support scope but still be usuable as asp.netcore 2.2 considered as unique category and continued its legacy.
Example:
namespace IFromFileTestClassLibrary
{
public class UploadFiles
{
public async Task<string> FileHandelerMethod(CreateProfileViewModel requestModel)
{
string filePath = "file saving path";
var path = Path.Combine(filePath, "Images", requestModel.Photo!.FileName);
if (requestModel.Photo.Length > 0)
{
using var stream = new FileStream(path, FileMode.Create);
await requestModel.Photo.CopyToAsync(stream);
}
return requestModel.ImageURL = path;
}
}
public class CreateProfileViewModel
{
public string? ProfileName { get; set; }
public string? DisplayPhoto { get; set; }
public string? ImageURL { get; set; }
public IFormFile? Photo { get; set; }
}
}
Note: You can refer to this official document for more details.
答案2
得分: 2
请阅读此文档:
https://docs.microsoft.com/en-us/aspnet/core/fundamentals/target-aspnetcore
在 .csproj 文件中删除任何类似 Microsoft.Extensions.Features 的包,并改为引用框架。
<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>
英文:
Please read this document:
https://docs.microsoft.com/en-us/aspnet/core/fundamentals/target-aspnetcore
Delete any packages like Microsoft.Extensions.Features in the .csproj file and instead reference the framework.
<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论