asp.net下载Object
回1楼梦丫头的帖子
asp.net 把云服务器上的文件下载到本地。
-------------------------
Reasp.net下载Object
搞定
public static bool SaveObject(string Path, string fileName)
{
try
{
OssObject ossObj = new OssClient(accessId, accessKey).GetObject(bucketName, fileName);
if (ossObj.Metadata.ContentLength == 0)
{
return false;
}
Stream ossContent = ossObj.Content;
FileStream fs = new FileStream(Path + fileName, FileMode.Create);
byte[] buffer = new byte[1024];
int i = 0;
do
{
i = ossContent.Read(buffer, 0, buffer.Length);
if (i > 0)
{
fs.Write(buffer, 0, i);
}
} while (i > 0);
ossContent.Close();
fs.Close();
return true;
}
catch (OssException ex)
{
return false;
}
}
赞0
踩0