How to calculate file size in mb

Hi Team,

  1. I want to calculate file size in MB.

2)If file size is grater than 20 MB then file should get split & if file size is less than 20 MB then file should not get split. how i can use if else condition for this?

Please help me…

Hi @Smitesh_Aher2 ,

Use Get_File Info Activity to get the file size in KB and convert it into MB and add condition to check if file size is greater than 20 MB or not, check the attached flow for your reference hope it works for you…

image

Regards,
Vinit Mhatre

Hi @Smitesh_Aher2

please check below:
Sequence48.xaml (8.5 KB)

Regards

Hi,

How about the following expression?

(New FileInfo("yourFile")).Length \ (1<<20) > 20

Regards,

Thanks @Vinit_Mhatre , @Yoichi & @vrdabberu for your response.

  1. I want to calculate file size in MB. —> This is working now.

2)If file size is grater than 20 MB then file should get split & if file size is less than 20 MB then file should not get split. how i can use if else condition for this?----> help me on this.

In the 2nd case if file size is 50mb then how to split file in 3 part like below,
1)1st file size - 20MB
2)2nd file size - 20MB
3)3rd file size - 10MB

any solution on this? please let me know.

Hi,

Can you also share what file type and how do you want to split?

Regards,

Hi @Yoichi

1)File is in .pdf format.

  1. As per your given condition if file size is less than 20MB then no need of split file & if file size is grater than 20MB then file should get split like below,
    If file size is 50mb then file should get split in 3 part like below,
    1)1st file size - 20MB
    2)2nd file size - 20MB
    3)3rd file size - 10MB

Hi,

Can you share how split the pdf file? If we split the 50MB file to exact 20MB,20MB and 10MB files with byte base, we cannot open and read these files because they don’t have correct pdf format.(Howvere if we concatenate theses files, we can read it) Is this same with your requirement?

Regards,

Means we can’t split the large pdf file? right

Actually In my project we can upload file whose size is upto 20mb & we can’t upload file whose size is grater than 20mb.

Splitting of file size is not fix. like below,

1)1st file size should be like- 10mb or 5mb or 3mb…any
2)2nd file size - 3mb or 8mb or 3mb…any
3)3rd file size - 14mb or 5mb or 6mb…any

If you have anyother solution for this let me know.

HI,

ExtractPDFPageRange activity can extract specific pdf pages from pdf file. So the most easiest but in-effecient way is to split the pdf to each page, then upload, if file size is greater than 20MB.

Or we may be able to create logic to split file more efficient way using some algorithm.

Regards,

we may be able to create logic to split file more efficient way using some algorithm. ----> If you found any algorithm then let me know. it will be much more helpful for us.

HI,

how about the following sample? This sample divides into 2 files if the file is greater than 20MB and works with recursive logic.

Sample
Sample20240214-4.zip (4.6 KB)

note: please modify content of filepath and intChunkSize if necessary

Regards,

The only way to split a pdf into usable sub-documents is to split on a page level. The pages however are probably not equal in size depending on the amount and type of content.

I’d split the entire document into individual pages. (use pdf activities).
If any of the single pages > 20 MB you have an exception
Then, use the pdf merge activities to join sums of pages that total < 20 MB.

Thanks @Yoichi … Your code is working fine but you are splitting on basis on page number.

For eg:-
In case, if pdf size is 90mb then multiple file will get split as per your code and our upload limit is only 10 nos of file so, we can’t upload multiple file(more than 10) of single pdf.

Our limit for upload split file is only 10. so, we can’t upload beyond limit.

Any solution for this?

Basically, it’s difficult to split PDF by anything other than page because pdf is page based.
If you can accept to concatenate all the split files when downloading then open the file as pdf, we can split it by byte length based. (This means we cannot open each split file independently.)

Regards,

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.