每次我运行以下代码时,文件都会保存在硬盘驱动器上。但是,我希望仅将其保存在“对象存储”容器中。
OSClient os = OSFactory.builder()
.endpoint("...")
.credentials("...","...")
.tenantName("...")
.authenticate();
String containerName = "MyImgs";
String objectName = "test.jpg";
BufferedWriter output = null;
try {
File f = new File(objectName);
output = new BufferedWriter(new FileWriter(f));
output.write(text);
String etag = os.objectStorage().objects().put(containerName,
objectName,
Payloads.create(f));
} catch ( IOException e ) {
e.printStackTrace();
}
更新:我正在使用此API。
查看Javadoc的有效负载,它具有一个使用InputStream的方法。要将字符串读取为InputStream,可以执行以下操作
Payloads.create(new ByteArrayInputStream(text.getBytes());
这样可以避免只需要阅读一些文件就可以创建文件。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句