cancel
Showing results for 
Search instead for 
Did you mean: 

file uploads

smruti_moharana
Participant
0 Kudos

Dear Friends,

when i am trying upload the same image it is throughing error,to avoid it i want to add random number to the filr before its extension likeimage1.jpg and image2.jpg i am new to this please guide me to proceed .

Thanks,

Smruti Ranjan Moharana

Accepted Solutions (1)

Accepted Solutions (1)

junwu
Active Contributor
0 Kudos

can you share more ? what are you are trying to do?

cannot understand why you have problem to add some number after the name.......

smruti_moharana
Participant
0 Kudos

When i am trying to upload the same message twice it does not allow me to do that means it does not allow the duplicale image to upload, please guide me how to upload the same image number of times , please guide me to do that.

Thanks & Regards,

Smruti Ranjan Moharana

junwu
Active Contributor
0 Kudos

where you will write this img to ?

for upload, it won't prevent you from uploading same img.

smruti_moharana
Participant
0 Kudos

i am saving this images in kM folder

Thanks & Regards,

Smruti Ranjan Moharana

junwu
Active Contributor
0 Kudos

when you write to km, just give it a new name.

i don't see there is any issue.

Former Member
0 Kudos

Hi,

You cant store the same file, into the same folder path, more than once in KM.

KM has the concept of RID(Resource ID), which is defined by the file path. For example if you store a file named File1.txt under say documents folder, then the RID of the file will be /documents/File1.txt. And since RID should be unique, It will not allow you to store any other file (or the same file) with the same name into the same folder path.

Alternate solution will be to append the file name with the current system time stamp or different index every time you upload the file.

Regards,

Vishweshwara P.K.M.

smruti_moharana
Participant
0 Kudos

Dear Vishwa,

It is a very useful answer please guide me to add timestamp to the file or to add index .

Thanks & Regards,

Smruti Ranjan Moharana

Former Member
0 Kudos

Hi,

You can use the below snippet to append time stamp.


int positonOfDot = fileName.lastIndexOf(".");
String fileExtn = "";
String fileName_withoutExtn = "";
String timestamp = "";
Date currentDate = new Date();
SimpleDateFormat sysTimeStamp = new SimpleDateFormat("yyyyMMddHHmmss");
timestamp = sysTimeStamp.format(currentDate);
if(-1 != positonOfDot){
fileExtn = fileName.substring(positonOfDot + 1);
fileName_withoutExtn = fileName.substring(0, positonOfDot);
fileName = fileName_withoutExtn + "_" + timestamp + "." + fileExtn;
}

Where fileName is the String variable holding the name of the file.

Regards,

Vishweshwara P.K.M.

smruti_moharana
Participant
0 Kudos

Viswa Bhai,

Thanks alot it will working fine please guide me how to add index to filename,then it is agreat help to me and i will close my question

Thanks ,

smruti moharana

Former Member
0 Kudos

Hi,

Appending index to filename, i ment append "(1)" to the existing file name, instead of timestamp as shown below


fileName = fileName_withoutExtn + "(1)." + fileExtn;

But appending timestamp would be a better approch.

Regards,

Vishweshwara P.K.M.

Answers (0)