How can I Embed a file in a web app?

7 visualizzazioni (ultimi 30 giorni)
Ding Yong
Ding Yong il 18 Set 2021
Risposto: Tridib il 22 Apr 2025
Hi guys:
My web app wants to implement such a function:
Embed a PPT or PDF document into the program, and then when the user clicks the download button, the document can be downloaded locally. I tried to use uigetfile, but I couldn't realize this function. What should I do?

Risposte (1)

Tridib
Tridib il 22 Apr 2025
“uigetfile” function will not work here because it is used for opening files, not saving. “uiputfile” function is used for saving files.
  • Firstly, place the desired PPT or PDF file in the same folder as the .mlapp file.
  • Then, add the following code to the download button’s callback function:
% Button pushed function: Button
function ButtonPushed(app, event)
% Desired document
filename = 'mydoc.pdf';
% Getting the app's folder and then the desired file
appFolder = fileparts(mfilename('fullpath'));
sourceFile = fullfile(appFolder, filename);
% Asking the user where to save the file
[file, path] = uiputfile({'*.pdf;*.pptx','Documents (*.pdf, *.pptx)'}, ...
'Save As', filename);
if isequal(file,0)
return; % If user cancels
end
% Copying the file to the user's chosen location
destination = fullfile(path, file);
try
copyfile(sourceFile, destination);
uialert(app.UIFigure, 'Document downloaded successfully!', 'Success');
catch ME
uialert(app.UIFigure, ['Failed to download: ' ME.message], 'Error');
end
end
Through this, you will be able to achieve the required functionality in your app.
To create and deploy a corresponding web app for your app, refer to the following documentation:
For more information regarding the used functions, refer to the following documentation:
For more help, you may refer to a similar MATLAB answer:
Hope this helps!

Categorie

Scopri di più su MATLAB Web App Server in Help Center e File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by