gatsby-source-airtable icon indicating copy to clipboard operation
gatsby-source-airtable copied to clipboard

Mp3 files get converted to Mpga

Open wahidshafique opened this issue 4 years ago • 3 comments

I logged this issue here https://community.airtable.com/t/why-are-my-mp3-files-being-converted-to-mpga-when-downloaded-through-the-api/44200 thinking that it was a bug within Airtable itself, however now it seems as if this is caused by gatsby-source-airtable. I added a log point here https://github.com/jbolda/gatsby-source-airtable/blob/e85ea3c7c9f5c735fe0095dfe2c6e55321ab54d1/gatsby-node.js#L307 and noticed that all my mp3 files were coming in as mpga. Is there a particular reason for this?

wahidshafique avatar Nov 30 '21 22:11 wahidshafique

I think its actually the mime package itself that causes the mismatch, so perhaps its worth refining the approach here. I'm not exactly sure how the original commenter of that issue resolved it.

wahidshafique avatar Nov 30 '21 22:11 wahidshafique

Is the filename extension actually changed when it downloads or is it how gatsby processes and considers it?

jbolda avatar Dec 13 '21 15:12 jbolda

I think its how gatsby processes it and here was my ad-hoc fix

diff --git a/node_modules/gatsby-source-airtable/gatsby-node.js b/node_modules/gatsby-source-airtable/gatsby-node.js
index bdd512b..39e131f 100644
--- a/node_modules/gatsby-source-airtable/gatsby-node.js
+++ b/node_modules/gatsby-source-airtable/gatsby-node.js
@@ -304,7 +304,10 @@ const localFileCheck = async (
       // `data` is direct from Airtable so we don't use
       // the cleanKey here
       data[key].forEach((attachment) => {
-        const ext = mime.getExtension(attachment.type); // unknown type returns null
+        let ext = mime.getExtension(attachment.type); // unknown type returns null
+        if (ext === 'mpga') {
+          ext = 'mp3'
+        }
         let attachmentNode = createRemoteFileNode({
           url: attachment.url,
           store,

it seems to change only when its used in conjunction with the mime type package, nothing from Gatbsy or Airtable suggests that theres a transformation going on before that. Once there is a mismatch Gatsby completely forgets about the new mpga (I guess because it does not exist)

wahidshafique avatar Dec 13 '21 20:12 wahidshafique