java - Preserve image names in MySQL Blob -


i'm uploading images database in blobs file names being changed database_name-table_name.bin.png not good.

is there anyway preserve name application uploads them uses?

the java code (prepared statement) use upload them is:

fileinputstream inputstream = null;  // directory name want use file image = new file(createarticlecontroller.articledetails.get("introimg"));   inputstream = new fileinputstream(image);  pstmt.setbinarystream(7, (inputstream) inputstream,(int) (image.length())); 

database:

create table if not exists `temp_article` (   `id` int(11) not null auto_increment,   `title` varchar(200) collate utf8_unicode_ci not null,   `author` varchar(200) collate utf8_unicode_ci not null,   `author_id` int(10) not null,   `type` varchar(200) collate utf8_unicode_ci not null,   `date` timestamp not null default current_timestamp,   `wfurl` varchar(200) collate utf8_unicode_ci not null,   `intro` text collate utf8_unicode_ci not null,   `intro_image` mediumblob not null,   `status` int(10) not null default '0',   `main_image` mediumblob not null,   `content_1` text collate utf8_unicode_ci,   `image_1` mediumblob,   `content_2` text collate utf8_unicode_ci,   `image_2` mediumblob,   `content_3` text collate utf8_unicode_ci,   `image_3` mediumblob,   `content_4` text collate utf8_unicode_ci,   `image_4` mediumblob,       // images , content areas go on 17 of each   primary key (`id`)   ) engine=myisam  default charset=utf8 collate=utf8_unicode_ci auto_increment=2 ; 

there couple of factors going on here. first, you're not storing original filename anywhere. in order retrieve later, have store somewhere when upload. phpmyadmin tool administrators manage databases, , not designed view , download images. sure, you're able both of through it, mean since want manipulate downloaded file name, you'll need own customized software that; since phpmyadmin administrative tool isn't designed used that. bring third part, ultimate answer problem: download tool provide name. when write download portion of code, can have make file name, pull stored original file name database, or use generic default. it's code implement. you're (hopefully) not planning have end users download images through phpmyadmin, show code well.

so recap since longwinded: modify table structure add field store file name, store when creating, , retrieve when downloading.

also, (this secondary design principles) looks database design suffering lack of normalization (for instance see this, though there many, many articles it). time table has columns names image_1, image_2, , on it's indicator perform normalization on structure. additionally, you'll want store images in table away things title , author maintain access speed on non blob fields (generally speaking, blob columns seem slow down table access).


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -