Clear Filters
Clear Filters

Webwrite with .mlappinstall-file for artifactory-deployment

4 views (last 30 days)
We want to deploy updates for our appdesigner-apps (.exe as well as .mlappinstall) on our artifactory.
At the moment this is done manually. However, my goal is a matlab-script that
  1. compiles the app
  2. uploads it to its destination-folder on the artifactory.
My URL and login-informations are correct, I am able to deploy simple data (tested with a simple struct containing doubles and strings).
My question is, how to convert or pack an .mlappinstall for it to be sendable by webwrite.
I have found this FileExchange-solution for uploading to Dropbox via webwrite.
There they seem to encode an arbitrary file as char-array to put into webwrite. This naive approach doesn't work (it returns an empty char-array).
fid = fopen('myApp.mlappinstall', 'r');
data = char(fread(fid)');
Also, even if that would work, I would probably have difficulties to discern the correct MediaType and/or CharacterEncoding for the encoded .mlappinstall.
I would really appreciate suggestions for a proper workflow to do, what we want to achieve: compilation and artifactory-deployment of app-designer apps.
Also any help with encoding and sending apps or exe-files with webwrite would help us a lot.
Thank you.

Answers (1)

Sanchari
Sanchari on 3 Jun 2024
Edited: Sanchari on 3 Jun 2024
Hello Patrick,
Deploying MATLAB App Designer apps (.mlappinstall) or compiled apps (.exe) to an artifactory or any other type of repository programmatically involves a couple of steps. The process includes compiling the app (if necessary), encoding the file correctly, and then using an appropriate method to upload it to the server. Here's a step by step approach for the same:
1. Compiling the App
For compiled apps (.exe), one would use MATLAB's “mcc” command or the Application Compiler app. When aiming for automation, here's how one might compile an app from a script:
% Example for compiling a MATLAB app to an EXE (Requires MATLAB Compiler)
mcc('-m', 'yourAppMainFile.m', '-o', 'yourAppName');
For ".mlappinstall" files, one would use the "Package App" feature from the App Designer, which currently doesn't have a direct command-line equivalent for automation. However, once packaged manually, the update process can be automated.
2. Encoding and Preparing the File for Upload
To upload files using “webwrite”, firstly one has to correctly encode the file and then set the appropriate content type. For binary files like “.exe” or “.mlappinstall”, it should read the file in binary mode and use “uint8” for encoding. Here's how one can prepare the file for upload:
% Open the file in binary mode
fid = fopen('myApp.mlappinstall', 'rb');
data = fread(fid, '*uint8'); % Read as unsigned 8-bit integers
fclose(fid);
% Convert the data to a MATLAB web-friendly format
options = weboptions('MediaType','application/octet-stream');
3. Uploading the File
Assuming that a “REST API” is being used to communicate with the artifactory, the “webwrite” function can be used if it supports file uploads via the API. Consider refering to the artifactory's API documentation for the exact endpoints and methods. If “webwrite” doesn't meet the requirements (e.g., multipart/form-data support), one might need to use “webwrite” with custom options or investigate using "curl" through a system call for more complex interactions.
Here's a basic example using “webwrite”:
url = 'https://your.artifactory.url/path/to/upload'; % Change to the actual URL
filename = 'myApp.mlappinstall';
response = webwrite(url, 'file', data, options);
4. Using Curl for More Complex Uploads
If the upload process requires multipart/ form-data or other complex interactions that webwrite can't handle directly, then "curl" can be used through MATLAB's system command:
command = sprintf('curl -X POST -u username:password -F "file=@%s" %s', filename, url);
[status, cmdout] = system(command);
Replace “username:password” with the actual credentials (consider securely handling credentials) and adjust the curl command options as needed based on the artifactory's API.
Few things to be considered:
  • Ensure handling credentials securely. Avoid hardcoding them in the script. Consider using environment variables or secure vaults accessible from MATLAB.
  • Check the artifactory's API documentation for exact details on how to perform uploads. The examples provided here are generic and need to be adapted to fit the specific API's requirements.
  • For error handling and debugging, always check the output and status of the upload commands to ensure they're succeeding.
Please refer to the following references to know further about:
  1. Webwrite (MathWorks Documentation): https://www.mathworks.com/help/matlab/ref/webwrite.html?searchHighlight=webwrite&s_tid=srchtitle_support_results_1_webwrite
  2. Uploading a file with webwrite (ML Answer): https://www.mathworks.com/support/search.html/answers/262610-uploading-a-file-with-webwrite.html?fq%5B%5D=asset_type_name:answer&fq%5B%5D=category:matlab/internet-file-access&page=1
  3. Curl translation to webwrite (ML Answer): https://www.mathworks.com/support/search.html/answers/802011-curl-translation-to-webwrite.html?fq%5B%5D=asset_type_name:answer&fq%5B%5D=category:matlab/json-format&page=1
Hope this helps!

Categories

Find more on Package and Share Apps in Help Center and File Exchange

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!