Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8648983
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:26:48+00:00 2026-06-12T13:26:48+00:00

I am using GridFsOperations API of spring-data for mongodb to store large files in

  • 0

I am using GridFsOperations API of spring-data for mongodb to store large files in chunks in the db. Here is my code:

@Autowired
private GridFsOperations gridOperation;

public String save(InputStream inputStream, String contentType, String filename) {
  ...
  GridFSFile file = gridOperation.store(inputStream, filename, metaData);
  return file.getId().toString();
}

The code works fine but it always stores files in collections starting with prefix “fs”, which is the default in mongodb. Is there a way to specify a different prefix so that I can have different files and chunks for different kinds of files to be stored?

EDIT: additional question

How do I specify the chunk size? Is it advisable to have different chunk sizes for different kinds of files, for example – 2 mb for image files and 10 mb for video files?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T13:26:49+00:00Added an answer on June 12, 2026 at 1:26 pm

    I got solutions to both my questions (configure chunk sizes in my code and use different prefixes) using GridFS and GridFSInputFile classes instead of GridFSTemplate or GridFSOperations.

    I still want to know if its advisable to have different chunk sizes.

    For anybody who may want to know, here is the code snippet:

    @Autowired
    private MongoDbFactory dbFactory;
    
    public String save(InputStream inputStream, String contentType, String filename, String username, String bucket) {
      DBObject metaData = ....(create metadata here)
    
      GridFS gridFS = new GridFS(dbFactory.getDb(), bucket);
        GridFSInputFile gridFSInputFile = gridFS.createFile(inputStream);
        gridFSInputFile.setMetaData(metaData);
    
        if(bucket.equals("photo")){
            gridFSInputFile.setChunkSize(1024000);  //1 mb
        } else if(bucket.equals("mp3")){
            gridFSInputFile.setChunkSize(10240000); //10 mb
        }
    
        try {
            gridFSInputFile.saveChunks();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        gridFSInputFile.save();
    
        return gridFSInputFile.getId().toString();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using ASIHTTPRequest, I downloaded a zip file containing a folder with several audio files.
using Telerik.WinControls.Data; using Telerik.WinControls.UI.Export; namespace Directory { public partial class radForm : Form {
Using Android TelephonyManager an application can obtain the state of data activity over the
Using Core Data, I have a fetch request to fetch the minimum of a
Using EF Code First I have an model object that has multiple properties that
Using the HTML5 File API I can get the Binary String representation of a
Using C# and System.Data.SqlClient, is there a way to retrieve a list of parameters
Using the vim-latexsuite for Gvim, I am editing a fairly large document. It consists
using this code I can send one texture to the shader: devcon->PSSetShaderResources(0, 1, &pTexture);
Using Spring MVC, do interceptors only intercept defined controller mappings or can they also

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.