Limit attachment file size

A forum for questions or concerns related to the PDF-XChange Core API SDK

Moderators: TrackerSupp-Daniel, Tracker Support, Vasyl-Tracker Dev Team, Chris - Tracker Supp, Sean - Tracker, Tracker Supp-Stefan

Forum rules
DO NOT post your license/serial key, or your activation code - these forums, and all posts within, are public and we will be forced to immediately deactivate your license.

When experiencing some errors, use the IAUX_Inst::FormatHRESULT method to see their description and include it in your post along with the error code.
Post Reply
kinwind
User
Posts: 38
Joined: Tue May 31, 2016 7:03 am

Limit attachment file size

Post by kinwind »

Hi

Can I limit attachment file size?

for example, I don't allow user insert attachment file over 100MB size.

thanks
User avatar
Will - Tracker Supp
Site Admin
Posts: 6815
Joined: Mon Oct 15, 2012 9:21 pm
Location: London, UK
Contact:

Re: Limit attachment file size

Post by Will - Tracker Supp »

Hi kinwind,

Thanks for the email - I don't believe that this can be done currently, but I'll pass along a feature request.

Thanks,
If posting files to this forum, you must archive the files to a ZIP, RAR or 7z file or they will not be uploaded.
Thank you.

Best regards

Will Travaglini
Tracker Support (Europe)
Tracker Software Products Ltd.
http://www.tracker-software.com
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Limit attachment file size

Post by Sasha - Tracker Dev Team »

Hello kinwind,

As far as I know, you are using the Editor SDK. Did you mean to ask a question in the SDK forum thread to limit the size of the added attachments by code?

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
kinwind
User
Posts: 38
Joined: Tue May 31, 2016 7:03 am

Re: Limit attachment file size

Post by kinwind »

Hi.

very sorry

I am using the Editor SDK.

I need limit the size of the added attachments by code

thanks.
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Limit attachment file size

Post by Sasha - Tracker Dev Team »

Hello kinwind,

Here's the code snippet how this can be done:

Code: Select all

if (e.nEventID == nIDS[(int)IDS.e_operBeforeExecute])
{
	PDFXEdit.IOperation oper = (PDFXEdit.IOperation)e.pFrom;
	int opID = pdfCtl.Inst.Str2ID("op.attachments.addMulti", false);
	if (opID == oper.ID)
	{
		//Getting options
		PDFXEdit.ICabNode options = oper.Params.Root["Options"];
		//The data can be ether the FileNamesCollection or AttachmentsList
		PDFXEdit.ICabNode fnc = options["FileNamesCollection"];
		PDFXEdit.ICabNode al = options["AttachmentsList"];
		if (fnc != null)
		{
			PDFXEdit.IAFS_NamesCollection nc = fnc.v as PDFXEdit.IAFS_NamesCollection;
			if (nc != null)
			{
				PDFXEdit.IAFS_NamesCollection newNC = fsInst.CreateNames();
				for (uint i = 0; i < nc.Count; i++)
				{
					PDFXEdit.IAFS_Name name = nc[i];
					string str = name.FileSys.NameToString(name);
					//Here check the file by it's path and if the size is bigger is needed then we won't add it into the resulting collection
					newNC.Add(name);
				}
				options["FileNamesCollection"].v = newNC;
			}
		}
		else if (al != null)
		{
			PDFXEdit.IPXV_AttachList aList = al.v as PDFXEdit.IPXV_AttachList;
			if (al != null)
			{
				for (int i = (int)aList.Count - 1; i >= 0; i--)
				{
					PDFXEdit.IPXC_FileSpec fs = aList[(uint)i];
					//fs.EmbeddedFile.UnCompressedSize - checking this
					//If the uncompressed size is bigger then needed - remove the item from the aList
					//aList.Remove(i);
				}
				options["AttachmentsList"].v = aList;
			}
		}

	}
}
Do not forget to enable e.operBeforeExecute event listening to the Control.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
kinwind
User
Posts: 38
Joined: Tue May 31, 2016 7:03 am

Re: Limit attachment file size

Post by kinwind »

thank you , Sasha
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Limit attachment file size

Post by Sasha - Tracker Dev Team »

:)
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
kinwind
User
Posts: 38
Joined: Tue May 31, 2016 7:03 am

Re: Limit attachment file size

Post by kinwind »

Hi.. Sasha

I use the code snippet in our project.

But, when I click the button from toolbar I find the operation is "op.attachments.add" not "op.attachments.addMulti".

May you can help me

thanks
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Limit attachment file size

Post by Sasha - Tracker Dev Team »

Hello kinwind,

Well, the overall logic should be the same, only you should check the FileName property in the operation's Options cab node.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Post Reply