我正在构建一个中继服务,它将视频从外部服务器传递到YouTube。目前,我的代码运行正常,但我需要避免提前将文件保存在本地,以便使用MediaFileSource将文件上传到YouTube。有没有一种方法可以传递InputStream而不是文件,并使用MediaStreamSource来允许管道?
https://developers.google.com/gdata/javadoc/com/google/gdata/data/media/MediaStreamSource
这样,我就可以像这样直接通过管道传输文件
YouTubeService youTubeService = new YouTubeService("My-Service", developerKey);
youTubeService.setUserCredentials(user, password);
VideoEntry newEntry = new VideoEntry();
YouTubeMediaGroup mg = newEntry.getOrCreateMediaGroup();
mg.setTitle(new MediaTitle());
mg.getTitle().setPlainTextContent("Song Title");
mg.addCategory(new MediaCategory(YouTubeNamespace.CATEGORY_SCHEME, "Category"));
mg.setKeywords(new MediaKeywords());
mg.getKeywords().addKeyword("Test");
mg.setDescription(new MediaDescription());
mg.getDescription().setPlainTextContent("Song Description");
mg.setPrivate(false);
MediaStreamSource ms = new MediaFileSource(new URL("http://www.somewebsite.com/video.mp4").openStream(), "video/mp4");
newEntry.setMediaStream(ms);
String uploadUrl = "http://uploads.gdata.youtube.com/feeds/api/users/default/uploads";
VideoEntry createdEntry = youTubeService.insert(new URL(uploadUrl), newEntry);
return createdEntry.getHtmlLink().getHref();发布于 2014-01-23 19:50:06
我遇到了一个错误,不得不将我的代码编辑为:
String title = "Test Video";
youTubeService.getRequestFactory().setHeader("Slug", title);我想我应该提一下因为我没在你的片断里看到这个。但是上传的时间太长了。你的上传有什么进展吗?
https://stackoverflow.com/questions/20388267
复制相似问题