【发布时间】:2017-04-23 13:47:40
【问题描述】:
我一直在我的应用程序中使用 Gmail API,直到昨天它都运行良好,现在我得到了
V/Error: 400 Bad Request
{
"code" : 400,
"errors" : [ {
"domain" : "global",
"message" : "Request payload size exceeds the limit: 1048576 bytes.",
"reason" : "badRequest"
} ],
"message" : "Request payload size exceeds the limit: 1048576 bytes.",
"status" : "INVALID_ARGUMENT"
}
我是用multipart来附加文件的,这里是sn-p的代码
MimeMessage createEmailWithAttachment(String to,
String from,
String subject,
String bodyText,
File file)
throws MessagingException, IOException {
Properties props = new Properties();
Session session = Session.getDefaultInstance(props, null);
MimeMessage email = new MimeMessage(session);
email.setFrom(new InternetAddress(from));
email.addRecipient(javax.mail.Message.RecipientType.TO,
new InternetAddress(to));
email.setSubject(subject);
MimeBodyPart mimeBodyPart = new MimeBodyPart();
mimeBodyPart.setContent(bodyText, "text/plain");
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(mimeBodyPart);
mimeBodyPart = new MimeBodyPart();
DataSource source = new FileDataSource(file);
mimeBodyPart.setDataHandler(new DataHandler(source));
mimeBodyPart.setFileName(file.getName());
multipart.addBodyPart(mimeBodyPart);
email.setContent(multipart);
return email;
}
几天前它工作得很好,现在每当我尝试发送大于 1 MB 的文件时都会出现上述错误,有什么办法可以解决这个问题?
谢谢
【问题讨论】:
-
奇怪的是,这个问题只是在没有更改代码的情况下发生。你看过multipart upload吗?允许更大的消息大小。
-
我重试了一个旧的完美工作的样本,现在它也给出了同样的问题,我确信它曾经完美地工作过!