saving a file to the web(my server)
in
Contributed Library Questions
•
2 years ago
I've found the wiki article...
http://wiki.processing.org/w/Saving_files_to_a_web-server
It wants a byte array.
I've got an example code from Toxi..
.import toxi.geom.*;
import toxi.geom.mesh.*;
void setup() {
// define a rounded cube using the SuperEllipsoid surface function
SurfaceFunction functor=new SuperEllipsoid(0.3,0.3);
SurfaceMeshBuilder b = new SurfaceMeshBuilder(functor);
// execute the mesh (resolution=80, radius=100)
TriangleMesh mesh = (TriangleMesh)b.createMesh(null, 80, 100);
// attempt to create a FileOutputStream and save to it
try {
String fileID="superellipsoid-"+(System.currentTimeMillis()/1000);
FileOutputStream fs;
fs=new FileOutputStream(sketchPath(fileID+".stl"));
mesh.saveAsSTL(fs);
fs=new FileOutputStream(sketchPath(fileID+".obj"));
mesh.saveAsOBJ(fs);
}
catch(Exception e) {
e.printStackTrace();
}
exit();
}
which gives me a FileOutputStream. How would I convert the FileOutputStream into a byte array so that I can save it to my server? Or, is there a better way?
It wants a byte array.
I've got an example code from Toxi..
.import toxi.geom.*;
import toxi.geom.mesh.*;
void setup() {
// define a rounded cube using the SuperEllipsoid surface function
SurfaceFunction functor=new SuperEllipsoid(0.3,0.3);
SurfaceMeshBuilder b = new SurfaceMeshBuilder(functor);
// execute the mesh (resolution=80, radius=100)
TriangleMesh mesh = (TriangleMesh)b.createMesh(null, 80, 100);
// attempt to create a FileOutputStream and save to it
try {
String fileID="superellipsoid-"+(System.currentTimeMillis()/1000);
FileOutputStream fs;
fs=new FileOutputStream(sketchPath(fileID+".stl"));
mesh.saveAsSTL(fs);
fs=new FileOutputStream(sketchPath(fileID+".obj"));
mesh.saveAsOBJ(fs);
}
catch(Exception e) {
e.printStackTrace();
}
exit();
}
which gives me a FileOutputStream. How would I convert the FileOutputStream into a byte array so that I can save it to my server? Or, is there a better way?
1