我必须上传tfp图片以供用户头像使用。我在下面编写了该代码以进行上传。但是给定的表单文件目录存在一些问题。
我下面有要上传的代码。
select unumber, name, localid
from (select t1.*,
count(*) over (partition by unumber) as cnt,
row_number() over (partition by unumber, name, localid order by unumber) as seqnum
from table1 t1
) t1
where cnt > 1 and seqnum = 1;
这部分抛出错误:
public async Task<IActionResult> EditProfile(string username , EditProfileModel model , IFormFile file)
{
if (!ModelState.IsValid)
{
var url = Url.Action("EditProfile", new { username = username, durum = "basarisiz" });
return Redirect(url);
}
var user = await _userManager.FindByNameAsync(model.UserName);
if (user != null)
{
if (file != null)
{
FileInfo fileInfo = new FileInfo(file.FileName);
string url = "ftp://*MY SERVER IP*/httpdocs/wwwroot/assets/images";
FtpWebRequest FTP;
FTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(url));
FTP.Credentials = new NetworkCredential("*MYID*", "*MYPASSWORD*");
FTP.KeepAlive = false;
FTP.Method = WebRequestMethods.Ftp.UploadFile;
FTP.UseBinary = true;
FTP.ContentLength = fileInfo.Length;
int buffLenght = 2048;
byte[] buff = new byte[buffLenght];
int contentLenght;
FileStream FS = fileInfo.OpenRead();
try
{
Stream strm = FTP.GetRequestStream();
contentLenght = FS.Read(buff, 0, buffLenght);
while (contentLenght != 0)
{
strm.Write(buff, 0, buffLenght);
contentLenght = FS.Read(buff, 0, buffLenght);
}
strm.Close();
FS.Close();
}
catch (Exception)
{
throw;
}
}
other parts of the code...
错误说找不到文件,因为例如我从桌面上传了一张照片,但是在发布表单时,表单文件具有以下目录:
MyProjectDirectory \ imagename.jpg