Git Product home page Git Product logo

Comments (3)

ckru-kiel avatar ckru-kiel commented on July 26, 2024

I created two functions and uploaded them to branch feature/79-upload-file-via-hasura-to-a-storage-bucket

  1. an Action(Mutation) to upload a file "saveFile".
    The Action has two parameters
    1. "base64file" which is a base 64 file blob
    2. "filename" the filename which can be a full path
      The Action has a respons value "link" which is a link to the uploaded file which is accessible for 5 minutes
      Example:
mutation saveFile {
  saveFile(base64file: "data:application/pdf;base64,JVBERi0xLjUKJcOkw7zDtsOfCjIgMCB...MGpVCwdiYWZtuglYNVFT0YK",  filename: "test/test.pdf")
}
  1. an Action(Query) to get a file link "loadFile".
    The Action has one parameter
  2. "filename" the filename which can be a full path
    The Action has a respons value "link" which is a link to the uploaded file which is accessible for 5 minutes
    Example:
query MyQuery {
   loadFile(path: "test/test.pdf") {
    link
  }
}

The functions need two environment variables to work:

  1. HASURA_CLOUD_FUNCTION_SECRET the secret can be found in our google-cloud-secret-manager
  2. HASURA_BUCKET the bucket name to determine which bucket to upload to

I have not done much in way of a proper error management such as html responses if something goes wrong or security such as checking for allowed file types and sizes etc.

from eduhub.

ckru-kiel avatar ckru-kiel commented on July 26, 2024

As of #209 this behavior has changed. There are now different actions for each file:

  • loadAchievementCertificate : gets a SignedUrl from google to the achievementCertificate specified in the path parameter that is valid for 5 minutes. the fitting path parameter can be gotten from the achievementCertificateUrl field of the CourseEnrollment table.
  • loadAchievementCertificateTemplate : gets a SignedUrl from google to the achievementCertificateTemplate specified in the path parameter that is valid for 5 minutes. the fitting path parameter can be gotten from the achievementCertificateTemplateUrl field of the Program table.
  • loadParticipationCertificate : gets a SignedUrl from google to the participationCertificate specified in the path parameter that is valid for 5 minutes. the fitting path parameter can be gotten from the participationCertificateUrl field of the CourseEnrollment table.
  • loadParticipationCertificateTemplate : gets a SignedUrl from google to the participationCertificateTemplate specified in the path parameter that is valid for 5 minutes. the fitting path parameter can be gotten from the participationCertificateTemplateUrl field of the Program table.
  • saveAchievementCertificate : saves the given achievementCertificate (encoded as a base64 file) to the google bucket. The return value is a relative path that should be saved in the achievementCertificateUrl field in the CourseEnrollment table to be used with the loadAchievementCertificate action
  • saveAchievementCertificateTemplate : saves the given achievementCertificateTemplate (encoded as a base64 file) to the google bucket. The return value is a relative path that should be saved in the achievementCertificateTemplateUrl field in the Program table to be used with the loadAchievementCertificateTemplate action
  • saveAchievementRecordCoverImage : saves the given achievementRecordCoverImage (encoded as a base64 file) to the google bucket. The return value is a url to a public file in the google bucket and should be saved in the coverImageUrl field of the AchievementRecord table for future retrieval
  • saveCourseImage : saves the given courseImage (encoded as a base64 file) to the google bucket. The return value is a url to a public file in the google bucket and should be saved in the coverImage field of the Course table for future retrieval
  • saveParticipationCertificate : saves the given participationCertificate (encoded as a base64 file) to the google bucket. The return value is a relative path that should be saved in the participationCertificateUrl field in the CourseEnrollment table to be used with the loadParticipationCertificate action
  • saveParticipationCertificateTemplate : saves the given participationCertificateTemplate (encoded as a base64 file) to the google bucket. The return value is a relative path that should be saved in the participationCertificateTemplateUrl field in the Program table to be used with the loadParticipationCertificateTemplate action
  • saveUserProfileImage : saves the given userProfileImage (encoded as a base64 file) to the google bucket. The return value is a url to a public file in the google bucket and should be saved in the picture field of the User table for future retrieval

from eduhub.

ckru-kiel avatar ckru-kiel commented on July 26, 2024
  • saveAchievementRecordDocumentation : saves the given achievementRecordDocumentation (encoded as a base64 file) to the google bucket. The return value is a relative path that should be saved in the documentationUrl field in the AchievementRecord table to be used with the loadAchievementRecordDocumentation action
  • loadAchievementRecordDocumentation : gets a SignedUrl from google to the achievementRecordDocumentation specified in the path parameter that is valid for 5 minutes. the fitting path parameter can be gotten from the documentationUrl field of the AchievementRecord table.

from eduhub.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.