List of usage examples for com.mongodb.gridfs GridFSInputFile setFilename
public void setFilename(final String filename)
From source file:net.tooan.ynpay.third.mongodb.fs.BuguFS.java
License:Apache License
public void save(File file, String filename, Map<String, Object> params) { GridFSInputFile f = null; try {// w w w . j a v a 2 s .com f = fs.createFile(file); } catch (IOException ex) { logger.error("Can not create GridFSInputFile", ex); } f.setChunkSize(chunkSize); f.setFilename(filename); setParams(f, params); f.save(); }
From source file:net.tooan.ynpay.third.mongodb.fs.BuguFS.java
License:Apache License
public void save(InputStream is, String filename, Map<String, Object> params) { GridFSInputFile f = fs.createFile(is); f.setChunkSize(chunkSize);//ww w. j a va2 s. c o m f.setFilename(filename); setParams(f, params); f.save(); }
From source file:net.tooan.ynpay.third.mongodb.fs.BuguFS.java
License:Apache License
public void save(byte[] data, String filename, Map<String, Object> params) { GridFSInputFile f = fs.createFile(data); f.setChunkSize(chunkSize);/*from w w w. j av a 2s . c o m*/ f.setFilename(filename); setParams(f, params); f.save(); }
From source file:net.ymate.platform.persistence.mongodb.support.GridFSFileBuilder.java
License:Apache License
public GridFSInputFile build(IGridFSSession gridFS) throws Exception { GridFSInputFile _inFile = null; switch (__type) { case 1: // is File _inFile = gridFS.getGridFS().createFile((File) __targetObject); break;//from ww w . ja va 2 s. co m case 2: // is InputStream _inFile = gridFS.getGridFS().createFile((InputStream) __targetObject); break; case 3: // is Array _inFile = gridFS.getGridFS().createFile((byte[]) __targetObject); } if (_inFile != null) { _inFile.setFilename(__filename); _inFile.setContentType(__contentType); if (__chunkSize > 0) { _inFile.setChunkSize(__chunkSize); } if (!__attributes.isEmpty()) { for (Map.Entry<String, Object> _entry : __attributes.entrySet()) { _inFile.put(_entry.getKey(), _entry.getValue()); } } } return _inFile; }
From source file:oecp.framework.fs.gridfs.GridxFS.java
License:Apache License
public GridFSInputFile save(File file, String filename, String folderName, Map<String, Object> params) { GridFSInputFile f = null; FileInputStream fileInputStream = null; try {// w w w . j a va 2 s. co m fileInputStream = new FileInputStream(file); f = fs.createFile(fileInputStream, file.getName()); } catch (Exception e) { logger.error(e.getMessage()); } f.setFilename(filename); setParams(f, folderName, params); f.save(); if (fileInputStream != null) {//? try { fileInputStream.close(); } catch (IOException e) { } } return f; }
From source file:oecp.framework.fs.gridfs.GridxFS.java
License:Apache License
public GridFSInputFile save(InputStream is, String filename, String folderName, Map<String, Object> params) { GridFSInputFile f = fs.createFile(is); f.setFilename(filename); setParams(f, folderName, params);//from w w w . j av a 2s .co m f.save(); return f; }
From source file:oecp.framework.fs.gridfs.GridxFS.java
License:Apache License
public GridFSInputFile save(byte[] data, String filename, String folderName, Map<String, Object> params) { GridFSInputFile f = fs.createFile(data); f.setFilename(filename); setParams(f, folderName, params);/* w w w . j ava 2 s . co m*/ f.save(); return f; }
From source file:org.craftercms.social.services.impl.SupportDataAccessImpl.java
License:Open Source License
@Override public ObjectId saveFile(MultipartFile file) throws IOException { GridFS gFS = new GridFS(mongoTemplate.getDb()); GridFSInputFile gFSInputFile = gFS.createFile(file.getInputStream()); gFSInputFile.setFilename(file.getOriginalFilename()); gFSInputFile.setContentType(file.getContentType()); gFSInputFile.save();/* ww w .j a v a 2 s . c o m*/ return (ObjectId) gFSInputFile.getId(); }
From source file:org.exist.mongodb.xquery.gridfs.Store.java
License:Open Source License
@Override public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException { try {//from w w w.ja va2 s . co m // Verify clientid and get client String mongodbClientId = args[0].itemAt(0).getStringValue(); MongodbClientStore.getInstance().validate(mongodbClientId); MongoClient client = MongodbClientStore.getInstance().get(mongodbClientId); // Get parameters String dbname = args[1].itemAt(0).getStringValue(); String bucket = args[2].itemAt(0).getStringValue(); String documentName = args[3].itemAt(0).getStringValue(); String contentType = getMimeType(args[4], documentName); LOG.info(String.format("Storing document %s (%s)", documentName, contentType)); // Actual content: File object, doc() element, base64... Item content = args[5].itemAt(0); // Get database DB db = client.getDB(dbname); // Creates a GridFS instance for the specified bucket GridFS gfs = new GridFS(db, bucket); // Create file GridFSInputFile gfsFile = gfs.createFile(); // Set meta data gfsFile.setFilename(documentName); gfsFile.setContentType(contentType); StopWatch stopWatch = new StopWatch(); // Write data if (StringUtils.endsWithAny(documentName, nonCompressables)) { writeRaw(gfsFile, stopWatch, content); } else { int dataType = content.getType(); writeCompressed(gfsFile, stopWatch, content, dataType); } LOG.info(String.format("serialization time: %s", stopWatch.getTime())); // Report identifier return new StringValue(gfsFile.getId().toString()); } catch (XPathException ex) { LOG.error(ex.getMessage(), ex); throw new XPathException(this, ex.getMessage(), ex); } catch (MongoException ex) { LOG.error(ex.getMessage(), ex); throw new XPathException(this, GridfsModule.GRFS0002, ex.getMessage()); } catch (Throwable ex) { LOG.error(ex.getMessage(), ex); throw new XPathException(this, GridfsModule.GRFS0003, ex.getMessage()); } }
From source file:org.exoplatform.mongo.service.impl.MongoRestServiceImpl.java
License:Open Source License
@POST @Consumes("multipart/form-data") @Path("/databases/{dbName}/collections/{collName}/binary") @Override//from ww w.j a va 2 s. c o m public Response createBinaryDocument(@PathParam("dbName") String dbName, @PathParam("collName") String collName, FormDataMultiPart document, @Context HttpHeaders headers, @Context UriInfo uriInfo, @Context SecurityContext securityContext) { if (shutdown) { return Response.status(ServerError.SERVICE_UNAVAILABLE.code()) .entity(ServerError.SERVICE_UNAVAILABLE.message()).build(); } Response response = null; String user = null; try { Credentials credentials = authenticateAndAuthorize(headers, uriInfo, securityContext); user = credentials.getUserName(); FormDataBodyPart file = document.getField("file"); String fileName = file.getContentDisposition().getFileName(); InputStream fileStream = file.getEntityAs(InputStream.class); GridFSInputFile gridfsFile = gridFs.createFile(fileStream); gridfsFile.setFilename(fileName); gridfsFile.save(); ObjectId documentId = (ObjectId) gridfsFile.getId(); if (documentId != null && !StringUtils.isNullOrEmpty(documentId.toString())) { URI statusSubResource = uriInfo.getBaseUriBuilder().path(MongoRestServiceImpl.class) .path("/databases/" + dbName + "/collections/" + collName + "/binary/" + documentId) .build(); response = Response.created(statusSubResource).build(); } else { response = Response.status(ServerError.RUNTIME_ERROR.code()) .entity(ServerError.RUNTIME_ERROR.message()).build(); } } catch (Exception exception) { response = lobException(exception, headers, uriInfo); } finally { updateStats(user, "createBinaryDocument"); } return response; }