Best answer

Create HTML file from string and pass it as a file to next steps

  • 25 April 2023
  • 3 replies
  • 652 views

Userlevel 2
Badge

Hi, I have an application that generates an HTML code and pushes it through a webhook. On Zapier, I want to catch that hook, create a file from the received HTML code and pass it along as a file to the next steps (in most cases I will need to add it as an attachment to Airtable, but I might pass it to other apps downstream as well).

I have tried to use Google Drive / Dropbox to create file from text content. But I cannot change the mime type of the file to HTML. I also failed to load the Google Drive file to Airtable from the provided Google Drive URL as it looses the filename in the process (which is odd). Either way I cannot use the file afterwards because of the wrong filename or wrong extension/mime type. This file will eventually reach SignRequest, which will convert the html file into pdf but only if it is interpreted as an html file (and not txt).

In the end of the day, creating a file on a temporary Google Drive folder, changing its mime and getting it back seems to be an unnecessary complication, creating a whole set o f new problems and I think it'd be best to find a simpler approach.

Ideally, I would be able to create an HTML file from a string on a Javascript code step and pass it along to the following steps, as an actual File.

Any help would be much appreciated.

 

 

 

icon

Best answer by sistemasUp 25 April 2023, 22:21

View original

This post has been closed for comments. Please create a new post if you need help or have a question about this topic.

3 replies

Userlevel 7
Badge +11

Great question, @sistemasUp! 👋
 

Hmm, maybe we need to take a slightly different approach here. Perhaps you could use another app to convert the txt file that’s created into a proper html file?

An app like ConvertAPI for example looks like it would do the trick. We also integrate with a number of other file conversion types of apps that you see in our File Management & Storage Apps category which make be worth checking out too. 

Do you think that approach could work for you here?

Userlevel 2
Badge

Hi, we managed to create the file on the original application with this code:

const formData = new FormData();
formData.append("file", new Blob([htmlCode], { type: "text/html" }) );
const Http = new XMLHttpRequest();
Http.open("POST", hook);
Http.send(formData);

I guess it would work after the webhook as well, on a code step, but in our case this was easier since I no longer need a code step and can upload the file directly into Airtable. 

Userlevel 7
Badge +9

Glad to hear you were able to get this sorted! Thanks for sharing your end solution with the community, @sistemasUp - I’m sure this’ll prove useful to others as well. 🙂