Re: FilePath On Upload Using Key Value Coding
Re: FilePath On Upload Using Key Value Coding
- Subject: Re: FilePath On Upload Using Key Value Coding
- From: email@hidden (Anjo Krank)
- Date: Tue, 31 Dec 2002 17:50:45 +0100
NSPathUtilities will only get the path for the current OS delimiters (:
and \ on Win, / on Unix). You need to replace every \ with / to
normalize that path, then get the file name via the last occurrence of
/.
so you need to do something like:
public void setPicThumbRef(String value) {
value = value.replace('\\', '/');
value = value.substring(value.lastIndexOf("/"), value.length());
takeStoredValueForKey(value, "picThumbRef");
}
and bind the filePath to "mypic.picThumbRef"
Cheers, Anjo
Am Dienstag, 31.12.02 um 16:24 Uhr schrieb Jonathan Fleming:
Hello all,
I'm having trouble understanding how to use the code below to get the
last component of a filepath into the database through a custom
EnterpriseObject created with the EOModel.
Here are the attributes/properties of the EOModel that we are
concerned with in a custom java file called TbJobPicture:
public NSData picThumbnail() {
return (NSData)storedValueForKey("picThumbnail");
}
public void setPicThumbnail(NSData value) {
takeStoredValueForKey(value, "picThumbnail");
}
public String picThumbRef() {
return (String)storedValueForKey("picThumbRef");
}
public void setPicThumbRef(String value) {
takeStoredValueForKey(value, "picThumbRef");
Normally in the fileUpload component I would bind the data to
tbJobPictureItem.picThumbnail & the filePath to
tbJobPictureItem.picThumbRef where tbJobPicture is the instance
variable (TbJobPicture tbJobPicture;). However, I want to put only the
last part of the file path into the database whereas the way I am
doing it at the moment I get the full path such as: C:\Documents and
Settings\All Users.WINXP\Documents\My Pictures\Sample
Pictures\Sunset.jpg
To get only Sunset.jpg I have to use the lastPathComponent() but it
can only be used on a String not a custom enterprise object like
TbJobPicture, thus the reason for going down the key value coding
route.
Basically How do I get the example I have been given below to convert
or save to the appropriate database field/property? My mind is shot to
pieces and I can not see the answer, simple though it may be to many
of you, I've been stuck on this for weeks.
I'd appreciate your help one and all
Regards
Jonathan
This is what was suggested to me, but I have failed to understand how
to use it.
Take advantage of key-value coding!
Bind the filePath attribute of your WOFileUpload element to something
like "myFilePath". In the component that contains the WOFileUpload
element, create two methods and an instance variable:
protected String myFilePath;
public void setMyFilePath(String aFilePath) {
myFilePath = NSPathUtilities.lastPathComponent(aFilePath);
}
public String getMyFilePath() {
return myFilePath;
}
Or if you want to hold onto the full path for other reasons you could
do the following instead:
public void setMyFilePath(String aFilePath) {
myFilePath = aFilePath;
}
public String getMyFilePath() {
return NSPathUtilities.lastPathComponent(myFilePath);
}
In either case, invoke getMyFilePath when you do whatever you need to
do to get the file name into the database field to which you allude.
_________________________________________________________________
Add photos to your e-mail with MSN 8. Get 3 months FREE*.
http://join.msn.com/?page=features/
featuredemail&xAPID=42&PS=47575&PI=7324&DI=7474&SU=
http://www.hotmail.msn.com/cgi-bin/
getmsg&HL=1216hotmailtaglines_addphotos_3mf
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.