Search code examples
node.jscalendargoogle-cloud-storageicalendar

How to serve an ics file through NodeJS API in a way that user can subscribe using URL?


So I have my ics file in Google Cloud Storage and I would like to serve it through my API so I don't have to make the ics file public. However, I am not sure what is the right way to do that so that the user can put the link to my api call in their Google Calendar as a webcal link to subscribe to the calendar.

Is this possible or do I have to provide a direct link to the ICS file for the user to be able to subscribe to the calendar? If it is possible, how would I go about serving the file in NodeJS?

Example: https://storage.googleapis.com/example/calendar.ics would be able to be served through https://api.com/example/userID/calendars

webcal://api.com/example/userID/calendars would then be used in the Google Calendars to subscribe to the calendar


Solution

  • So I had two options available to me:

    1. Change the access to the ICS file to public then share that URL to the user. However, this method would not allow me to dynamically change the file in the case that I would want to delete or change the file name.
    2. Serve the ICS file through my API - the method I had originally asked about in the original post.

    So for method 2, I basically just had to do gcs.bucket('bucket_name').file('file path to ics file in bucket').download((error, content) => res.send(content))