Skip to content

Error message not parsed for attachment bigger than 4Mb #260

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
5 tasks done
OlivierCuyp opened this issue Dec 17, 2019 · 4 comments
Closed
5 tasks done

Error message not parsed for attachment bigger than 4Mb #260

OlivierCuyp opened this issue Dec 17, 2019 · 4 comments

Comments

@OlivierCuyp
Copy link
Contributor

Bug Report

Prerequisites

  • Can you reproduce the problem?
  • Are you running the latest version?
  • Are you reporting to the correct repository?
  • Did you perform a cursory search?

For more information, see the CONTRIBUTING guide.

Description

The route [POST] /users/${userId}/messages/${messageId}/attachments only support attachment up to 4 Mb.

https://docs.microsoft.com/en-us/graph/api/message-post-attachments?view=graph-rest-1.0&tabs=http

This operation limits the size of the attachment you can add to under 4 MB.

When trying to POST bigger file than 4 MB the error returned from the API doesn't seem to be well parsed. Code & message are null.

Console Errors:

GraphError {
   statusCode: 500,
   code: null,
   message: null,
   requestId: null,
   date: 2019-12-17T15:00:55.823Z,
   body: null
}

Steps to Reproduce

  1. Create a new email with [POST] /users/${userId}/messages
  2. Add an attachment bigger than 4 Mb with [POST] /users/${userId}/messages/${messageId}/attachments
  3. You should get the error

Expected behavior: It would be nice to have an error message saying Attachment size limit exceeded in the error

Actual behavior: No message, no interesting info in the error

Additional Context

Usage Information

SDK Version - [SDK version you are using]

  • Node (Check, if using Node version of SDK)

Node Version - 10

@ghost ghost added the ToTriage label Dec 17, 2019
@OlivierCuyp
Copy link
Contributor Author

@darrelmiller sorry to ping you but linked to this issue I spotted a dead zone in attachment creation.

For file smaller than 4 Mb, we should use route

[POST] /users/${userId}/messages/${messageId}/attachments

https://docs.microsoft.com/en-us/graph/api/message-post-attachments?view=graph-rest-1.0&tabs=http

For file bigger than between 3Mb & 150 Mb, we should use the beta route

[POST]/users/${userId}/messages/${messageId}/attachments/createUploadSession

https://docs.microsoft.com/en-us/graph/api/attachment-createuploadsession

The first route is actually not limiting the byte size of the file but contentBytes payload which is base64 encoded.
Base64 takes +/- 37% more space than binary.
So the limitation of 4 Mb is in reality a limitation of 4Mb / 1.37 = 2.92 Mb.
It is then impossible to attach any file which has a size between 2.92Mb and 2.99Mb.

For this kind of file, the first route will result in:

GraphError {
   statusCode: 500,
   code: null,
   message: null,
   requestId: null,
   date: 2019-12-17T15:00:55.823Z,
   body: null
}

The second route will result in:

GraphError {
  statusCode: 400,
  code: 'ErrorAttachmentSizeShouldNotBeLessThanMinimumSize',
  message: 'Attachment size must be greater than the minimum size.',
  requestId: 'dc536b06-665d-4bb7-9c4e-285a2637b4e0',
  date: 2019-12-17T21:12:36.000Z,
  body: '{"code":"ErrorAttachmentSizeShouldNotBeLessThanMinimumSize","message":"Attachment size must be greater than the minimum size.","innerError":{"request-id":"dc536b06-665d-4bb7-9c4e-285a2637b4e0","date":"2019-12-17T22:12:36"}}'
}

I believe this is linked to the API limitation itself. So if I there is a better place to post this issue, let me know.

@OlivierCuyp
Copy link
Contributor Author

OlivierCuyp commented Dec 18, 2019

I did some more tests, and range of size having this issue seems smaller.
Here is the code to produce a file at specific size, 3145718 bytes file has the issue:

createFile.js

Usage: node createFile --size=3145718 --name=test.txt

const fs = require('fs');
const path = require('path');
const bytes = require('bytes');
const minimist = require('minimist');

const argv = minimist(process.argv.slice(2));

const letterBag = 'abcdefghijklmnopqrstuvwxyz ';

const getLetter = () => {
  const index = Math.floor(letterBag.length * Math.random());

  return letterBag[index];
};

const isNumber = data => !isNaN(data);

const main = async () => {
  try {
    const size = argv.size;
    if (!size) {
      throw new Error('Missing --size argument');
    }
    const parsedSize = isNumber(size)
      ? size
      : bytes.parse(size);
    const name = argv.name
      ? argv.name
      : 'test.txt';

    let text = '';
    for (let i = 0; i < parsedSize; i++) {
      text += getLetter();
    }

    fs.writeFileSync(path.join(__dirname, name), text);

    console.log(`File ${name} created!`);
  } catch (err) {
    console.error('Error:', err.message);
  }
};

main();

@nikithauc
Copy link
Contributor

@OlivierCuyp are you still experiencing this problem?

@nikithauc
Copy link
Contributor

Related to #359.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants