我使用官方的.net api客户端通过messages.send方法发送带有附件的电子邮件。当我附加一个大小超过5mb的文件时,
[JsonReaderException: Unexpected character encountered while parsing value: <. Path '', line 0, position 0.]
Newtonsoft.Json.JsonTextReader.ParseValue() +1187
Newtonsoft.Json.JsonTextReader.ReadInternal() +65
Newtonsoft.Json.JsonTextReader.Read() +28
Newtonsoft.Json.Serialization.JsonSerializerInternalReader.ReadForType(JsonReader reader, JsonContract contract, Boolean hasConverter) +237
Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent) +783
Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType) +293
Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings) +274
Newtonsoft.Json.JsonConvert.DeserializeObject(String value, JsonSerializerSettings settings) +57
Google.Apis.Json.NewtonsoftJsonSerializer.Deserialize(String input) in c:\code\google.com\google-api-dotnet-client\default\Tools\Google.Apis.Release\bin\Debug\test\default\Src\GoogleApis.Core\Apis\Json\NewtonsoftJsonSerializer.cs:120
Google.Apis.Services.<DeserializeError>d__8.MoveNext() in c:\code\google.com\google-api-dotnet-client\default\Tools\Google.Apis.Release\bin\Debug\test\default\Src\GoogleApis\Apis\Services\BaseClientService.cs:286
[GoogleApiException: An Error occurred, but the error response could not be deserialized]
Google.Apis.Requests.ClientServiceRequest`1.Execute() in c:\code\google.com\google-api-dotnet-client\default\Tools\Google.Apis.Release\bin\Debug\test\default\Src\GoogleApis\Apis\Requests\ClientServiceRequest.cs:102
我认为客户端使用元数据URI,仅用于元数据请求。A将尝试另一个选项:上传URI,用于媒体上传请求。看起来,电子邮件大小的限制导致了客户端库中解析错误响应的例外。
所以,第一个问题是:有尺寸限制吗?第二,没有关于如何通过客户端使用不同上传方式的信息,您知道任何客户端库文档吗?
更新:我黑掉了由
var request = gmailService.Users.Messages.Send(message, AccountUserId);
要去https://www.googleapis.com/gmail/v1/users/me/messages/send。正如我所设想的,它没有使用媒体上传请求。
发布于 2016-10-25 16:02:41
最后,我限制了附件的总大小。这是代码片段。
班级级别:
public const int MaxAttachmentsSize = 5 * 1024 * 1024;
方法级别:
var attachmentsSize = 0;
foreach (var attachment in attachments)
{
attachmentsSize += attachment.Item1;
if (attachmentsSize > MaxAttachmentsSize) break;
mailMessage.Attachments.Add(attachment.Item2);
}
发布于 2015-07-02 14:56:58
发布于 2015-07-06 17:27:11
对于任何超过几MB的内容(上传),您都应该使用该方法的/upload版本,否则您可能会遇到这些大小限制。
https://stackoverflow.com/questions/31187414
复制相似问题