natysoz / expo-images-picker

Multiple Asset Photos Videos selecting package for Expo SDK
MIT License
95 stars 35 forks source link

Converting to ReactNativeFile #21

Closed amosbastian closed 3 years ago

amosbastian commented 3 years ago

I am trying to convert the assets to a ReactNativeFile since this is what my upload endpoint (using graphql-upload) expects to receive. When using expo-image-picker and expo-image-picker-manipulator myself this works completely fine and the converted ReactNativeFile can be uploaded fine. Unfortunately when using your library it results in a ReactNativeFile with an undefined name and type. I am not sure why this is happening.

ReactNativeFile {
  "name": undefined,
  "type": undefined,
  "uri": "file:///Users/amosbastian/Library/Developer/CoreSimulator/Devices/5AA20A28-7243-4162-82E9-55D367BCA4E7/data/Containers/Data/Application/0A2F3C6C-E20D-4794-A50D-C643C44F0852/Library/Caches/ExponentExperienceData/%2540lifex%252Flifex-member/ImageManipulator/7B352BCB-A1B8-4A4E-85B2-51FE880E0F8D.png",
}
natysoz commented 3 years ago

i think when using the manipulator we might loss the type and name , ill check .

amosbastian commented 3 years ago

I managed to solve it for myself by doing this:

const files = assets.map(asset => {
  const file = new ReactNativeFile(asset);
  if (!file.type) {
    file.type = 'image/png';
  }
  if (!file.name) {
    file.name = Date.now() + '.png';
  }
  return file;
});