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:
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:
fid = fopen('myApp.mlappinstall', 'rb');
data = fread(fid, '*uint8');
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';
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:
- Webwrite (MathWorks Documentation): https://www.mathworks.com/help/matlab/ref/webwrite.html?searchHighlight=webwrite&s_tid=srchtitle_support_results_1_webwrite
- 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
- 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!