Directory:

1. Continue the previous hongmeng client upload files

2. The domain name penetrates through the Intranet tool

3. Python server-side code

4. The interface and business logic of Hongmeng mobile phone

5. “Hongmeng JS development mode” series of articles collection

1. Following on from the previous uploading file on Hongmeng client, upload the file on the Python server to Hongmeng mobile client. The specific implementation logic is as follows:

Request object module: import request from ‘@system.request’; Json file to set ohos.permission.INTERNET, which is accessed using HTTP protocol.

2. Use the Intranet penetration tool for the domain name or use other Intranet penetration tools. The ports through the domain name are the same as those on the Python server

3. The python server code is as follows:

from flask import Flask from flask import jsonify from flask import request import json import random from flask import send_from_directory @app.route("/download") def index(): Print (" executing file download ") return send_from_directory(r"D:\image\images",filename=" A0.jpg ", AS_attachment =True) if __name__=="__main__": app.run(debug=True,port=8500)Copy the code

4. The interface and business logic of Hongmeng mobile phone are as follows:

Interface construction code:

<div class="container"> <div class="downview" onclick="downoperator"><text class=" tvView "> download the file </text></div>Copy the code

Js business logic code is as follows:

import prompt from '@system.prompt'; import request from '@system.request'; Export default {data: {title: 'World'}, downoperator() {prompt. ShowToast ({message:" execute download file ", duration:8000}); request.download({ url: 'http://gjpwwj.natappfree.cc/download', success: function(data) { console.log('call success callback success: ' + data.token); }, fail: function(data, code) { console.log('handling fail'); }}); }}Copy the code

Download the file successfully, hongmeng will notify you with notification message:

Click on the notification bar to preview the downloaded file:

Using the Hilog log tool, you can also view the download success message:

Hongmeng’s time has come, embrace actively, Zhang Rongchao’s first lesson yesterday was very good, come on together!

Author: Liu He li Xin

For more information, visit Harmonyos.51cto.com, a collaboration between 51CTO and Huawei