在没有2个导出的情况下显示图像,可以通过以下几种方式实现:
<img src="image.jpg" alt="图像">
from flask import Flask, send_file
app = Flask(__name__)
@app.route('/')
def display_image():
return send_file('image.jpg', mimetype='image/jpeg')
if __name__ == '__main__':
app.run()
const COS = require('cos-nodejs-sdk-v5');
const fs = require('fs');
const cos = new COS({
SecretId: 'your-secret-id',
SecretKey: 'your-secret-key',
});
exports.main_handler = async (event, context, callback) => {
const params = {
Bucket: 'your-bucket',
Region: 'your-region',
Key: 'image.jpg',
};
const downloadPath = '/tmp/image.jpg';
await new Promise((resolve, reject) => {
cos.getObject(params, (err, data) => {
if (err) {
reject(err);
} else {
fs.writeFileSync(downloadPath, data.Body);
resolve();
}
});
});
return {
statusCode: 200,
headers: {
'Content-Type': 'image/jpeg',
},
body: fs.readFileSync(downloadPath).toString('base64'),
isBase64Encoded: true,
};
};
以上是三种常见的方法来在没有2个导出的情况下显示图像。具体使用哪种方法取决于你的需求和技术栈。
领取专属 10元无门槛券
手把手带您无忧上云