OneNote api下载图像

OneNote api download image

本文关键字:图像 下载 api OneNote      更新时间:2023-09-26

我正在尝试检索onenote页面的图像列表。当我得到页面内容,一个HTML,图像有一个来源的形式:

https://www.onenote.com/api/beta/resources/{id}/$value

通过对该url的处理,我得到了以下标题:

{
  'cache-control': 'no-cache',
  pragma: 'no-cache',
  'content-type': 'application/octet-stream',
  expires: '-1',
  server: 'Microsoft-IIS/8.0',
  'x-correlationid': '38283de4-110c-4c17-a371-c950c88025de',
  'x-usersessionid': '38283de4-110c-4c17-a371-c950c88025de',
  'x-officefe': 'OneNoteServiceFrontEnd_IN_2',
  'x-officeversion': '16.0.3429.1562',
  'x-officecluster': 'eus-www.onenote.com',
  p3p: 'CP="CAO DSP COR ADMa DEV CONi TELi CUR PSA PSD TAI IVDi OUR SAMi BUS DEM NAV STA UNI COM INT PHY ONL FIN PUR"',
  'x-content-type-options': 'nosniff',
  'request-processing-time': '31.2529 ms',
  'content-disposition': 'attachment',
  'preference-applied': 'odata.include-annotations=*',
  'x-aspnet-version': '4.0.30319',
  'x-powered-by': 'ASP.NET',
  date: 'Sat, 01 Nov 2014 00:17:25 GMT',
  'content-length': '10672' 
}

而这个响应的主体是一个大的二进制。

我正在使用Node Js应用程序进行此操作。

有人能给我一个如何将响应保存到图像文件(如png或jpeg)中的示例吗?提前感谢

经过一些额外的研究,我想出了如何做到这一点。

代码:

downloadFile: function (url, fileName, callback)
	{
		var options = {
				url: url
			,	encoding: null
			,	headers:  {'Authorization': 'Bearer ' + this.context.accessToken}
			};
		request.get(options, function (e, httpResponse, body)
		{
			var buffer = new Buffer(body, 'binary');
			fs.writeFile(fileName, buffer, function(err)
			{
				if(err)
				{
					console.log(err);
					throw err;
				}
				else
				{
					callback()
				}
			});
		});
	}

这里的重要部分是:

  1. encoding:null,否则request(npm模块)将把您的身体当作字符串
  2. 您必须知道OneNote将所有图像都视为.emf,否则您将转换或保存为该文件格式