如题,比如根据用户信息生成二维码,生成静态文件,再调用。可是云平台不支持写操作,所以图片无法本地保存,也就无法保存,大家有没有解决办法?如果不要求持久化,干脆不生成图片,base64 会报类型错误,TypeError: must be convertible to a buffer, not PilImage,这个要怎么做?
还有如果用云存储,也要生成图片才能上传上去。
You can generate a temporary file (the system temporary directory, it is impossible to block this directory, otherwise the file cannot be uploaded) and write the binary content of the image into it. Then submit this temporary file and delete it after completion. For example (PHP example):
class file {
private $file = null;
public function __construct($content=null) {
$this->file = tempnam(sys_get_temp_dir(),md5(uniqid().mt_rand()));
if ($content) {
$this->write($content);
}
}
public function write($content) {
file_put_contents($this->file,$content);
}
public function read($content) {
return file_get_contents($this->file);
}
public function getFilepath() {
return $this->file;
}
public function __destruct() {
@unlink($this->file);
}
}
I feel like this is not a general idea. Most cloud platforms have storage and you just need to use this function
If it is Sina Cloud, refer to the thumbnail generation and processing imagegif/imagejpeg/imagepng on SAE, which is similar.
You can generate a temporary file (the system temporary directory, it is impossible to block this directory, otherwise the file cannot be uploaded) and write the binary content of the image into it. Then submit this temporary file and delete it after completion. For example (PHP example):
python. Don’t know