Hi,
Is there any option to customize http request (add auth header) when downloading a file in SurveyCreator.
I've customize upload according to https://surveyjs.io/survey-creator/examples/file-upload/reactjs#content-code and url appears in my survey json definition, but images are not displayed as not able to add auth header for a download.
Thanks,
Piotr
Hello Piotr,
You can include required request headers when you send an HTTP request in the creator.onUploadFile event.
Below is the modified demo code which uses Fetch API to include headers.
fetch("https://api.surveyjs.io/private/Surveys/uploadTempFiles", { method: "POST", headers: { "Content-Type": "multipart/form-data", "Authorization": "Bearer <your_access_token>", "Other-Header": "<other_header_value>" }, body: formData }).then((response) => response.json()) .then((result) => { options.callback( "success", // A link to the uploaded file "https://api.surveyjs.io/private/Surveys/getTempFile?name=" + result[options.files[0].name] ); }) .catch((error) => { console.error("Error: ", error); });
Please let me know if you have any questions.
Sorry but your fragment is just for an upload which I've already implemented. As a result the survey json definition contains link rather than embedded image. But later the file needs to be displayed. I wonder how I can customize request downloading and displaying it as getting 401 at the moment.
Hello Piotr,
Thank you for the update. From what I gather, you wish to include HTTP request headers when an Image question makes a server request to load an image by the specified URL. Please confirm this.
I am talking about the stage when we are creating a survey in a SurveyCreator, so it doesn't have to be a question but also image logo at the top of the page, but I mean a design canvas.
Hello Piotr,
I understand that you wish to pass request headers to allow a survey to download images such as survey logo and image questions. Please let me check how to complete this. I'll update this ticket shortly.