我已经使用API修改了视频的缩略图。我尝试使用文件大小为1.37MB的PNG图片。上传后的状态为:
“ Google.Apis.Requests.RequestError \ r \ n媒体太大。限制:2MB [413] \ r \ nErrors [\ r \ n \ tMessage [媒体太大。限制:2MB]位置[-]原因[uploadTooLarge]域[全局] \ r \ n] \ r \ n“
如果我直接通过youtube.com更改缩略图,则缩略图将被上传并成功更新。
下面是我上载的代码。 _image由Image.FromFile()加载。我不确定为什么会失败:
public bool SetThumbnail(string _videoId, Image _image) {
using (MemoryStream m = new MemoryStream()) {
string imageFormat = null;
_image.Save(m, _image.RawFormat);
//Populate the correct image format that the YouTubeApi expects
if (ImageFormat.Jpeg.Equals(_image.RawFormat))
imageFormat = "image/jpeg";
else if (ImageFormat.Bmp.Equals(_image.RawFormat))
imageFormat = "image/bmp";
else if (ImageFormat.Gif.Equals(_image.RawFormat))
imageFormat = "image/gif";
else if (ImageFormat.Png.Equals(_image.RawFormat))
imageFormat = "image/png";
if (imageFormat != null) {
try {
var thumbnail = ytService.Thumbnails.Set(_videoId, m, imageFormat);
var r = thumbnail.UploadAsync().Result;
return r.Status == UploadStatus.Completed;
}
catch (GoogleApiException ex) {
LogFile.Instance.WriteLog(ex);
}
}
}