Exemplo n.º 1
0
exports.autoOrientJPEG = async attachment => {
  if (!MIME.isJPEG(attachment.contentType)) {
    return attachment;
  }

  const dataBlob = await arrayBufferToBlob(
    attachment.data,
    attachment.contentType
  );
  const newDataBlob = await dataURLToBlob(await autoOrientImage(dataBlob));
  const newDataArrayBuffer = await blobToArrayBuffer(newDataBlob);

  // IMPORTANT: We overwrite the existing `data` `ArrayBuffer` losing the original
  // image data. Ideally, we’d preserve the original image data for users who want to
  // retain it but due to reports of data loss, we don’t want to overburden IndexedDB
  // by potentially doubling stored image data.
  // See: https://github.com/signalapp/Signal-Desktop/issues/1589
  const newAttachment = Object.assign({}, attachment, {
    data: newDataArrayBuffer,
    size: newDataArrayBuffer.byteLength,
  });

  // `digest` is no longer valid for auto-oriented image data, so we discard it:
  delete newAttachment.digest;

  return newAttachment;
};
Exemplo n.º 2
0
 }, (err, body, res) => {
   if (err) throw err;
   const typeOfFile = fileType(new Uint8Array(res));
   blobUtil.arrayBufferToBlob(res, typeOfFile.mime)
   .then(blobUtil.createObjectURL)
   .then(objectURL => {
     dispatch({
       type: ActionTypes.SET_BLOB_URL,
       name: file.name,
       blobURL: objectURL
     });
   });
 });