L9: Content Type?

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

L9: Content Type?

Marc Pinnell-3
Working with a directory full of images (and a few other files). I would like to pull a list of ONLY image files for further processing. Seems like this should work, but the "contenttype" is throwing an error ( Error Code: -9948 Error Msg: Definition Not Found: file->contentType() ):

        with fname in dir(#path)->eachFile do {

                if(#fname->contenttype >> $allowedPixFileTypes) => {
                        #returnFileNames->insert(#path + #fname->name)
                }

        }

BTW - $allowedPixFileTypes is an array of extensions (.jpg, .jpeg, etc). Not sure if that is the right format for the conditional. Can't test since I can't seem to pull the content type.

What am I missing?

marc


Marc Pinnell
1027 Design
PO Box 990872
Redding, CA 96099-0872
530.941.4706
fax: 866.232.5300
www.1027Design.com



#############################################################

This message is sent to you because you are subscribed to
  the mailing list Lasso [hidden email]
Official list archives available at http://www.lassotalk.com
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: L9: Content Type?

Ke Carlton-3
 with file in dir(#path)->eachFile do {
                if($allowedPixFileTypes >>
#file->name->splitextension('.')->value ) => {
                        #returnFileNames->insert(#path + #file->name)
                }
 }



On 22 October 2014 18:01, Marc Pinnell <[hidden email]> wrote:

> Working with a directory full of images (and a few other files). I would
> like to pull a list of ONLY image files for further processing. Seems like
> this should work, but the "contenttype" is throwing an error ( Error Code:
> -9948 Error Msg: Definition Not Found: file->contentType() ):
>
>         with fname in dir(#path)->eachFile do {
>
>                 if(#fname->contenttype >> $allowedPixFileTypes) => {
>                         #returnFileNames->insert(#path + #fname->name)
>                 }
>
>         }
>
> BTW - $allowedPixFileTypes is an array of extensions (.jpg, .jpeg, etc).
> Not sure if that is the right format for the conditional. Can't test since
> I can't seem to pull the content type.
>
> What am I missing?
>
> marc
>
>
> Marc Pinnell
> 1027 Design
> PO Box 990872
> Redding, CA 96099-0872
> 530.941.4706
> fax: 866.232.5300
> www.1027Design.com
>
>
>
> #############################################################
>
> This message is sent to you because you are subscribed to
>   the mailing list Lasso [hidden email]
> Official list archives available at http://www.lassotalk.com
> To unsubscribe, E-mail to: <[hidden email]>
> Send administrative queries to  <[hidden email]>
>

#############################################################

This message is sent to you because you are subscribed to
  the mailing list Lasso [hidden email]
Official list archives available at http://www.lassotalk.com
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: L9: Content Type?

Wade Maxfield
In reply to this post by Marc Pinnell-3
On 22/10/2014, at 6:01 PM, Marc Pinnell <[hidden email]> wrote:

>
> with fname in dir(#path)->eachFile do {
>
> if(#fname->contenttype >> $allowedPixFileTypes) => {
> #returnFileNames->insert(#path + #fname->name)
> }
>
> }
>
> BTW - $allowedPixFileTypes is an array of extensions (.jpg, .jpeg, etc). Not sure if that is the right format for the conditional. Can't test since I can't seem to pull the content type.
>
> What am I missing?

One thing that looks odd to me is the logic.  The contenttype should not contain an array, but the array could contain the contenttype.

I think it should be more like:

if($allowedPixFileTypes >> #fname->contenttype) => {

}

 - Wade



#############################################################

This message is sent to you because you are subscribed to
  the mailing list Lasso [hidden email]
Official list archives available at http://www.lassotalk.com
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: L9: Content Type?

Marc Pinnell-3
In reply to this post by Ke Carlton-3
Doesn't this assume that the extension matches the actual content type? Am I trying to get something that doesn't exist?

marc


On Oct 21, 2014, at 10:13 PM, Ke Carlton <[hidden email]> wrote:

> with file in dir(#path)->eachFile do {
>                if($allowedPixFileTypes >>
> #file->name->splitextension('.')->value ) => {
>                        #returnFileNames->insert(#path + #file->name)
>                }
> }
>
>
>
> On 22 October 2014 18:01, Marc Pinnell <[hidden email]> wrote:
>
>> Working with a directory full of images (and a few other files). I would
>> like to pull a list of ONLY image files for further processing. Seems like
>> this should work, but the "contenttype" is throwing an error ( Error Code:
>> -9948 Error Msg: Definition Not Found: file->contentType() ):
>>
>>        with fname in dir(#path)->eachFile do {
>>
>>                if(#fname->contenttype >> $allowedPixFileTypes) => {
>>                        #returnFileNames->insert(#path + #fname->name)
>>                }
>>
>>        }
>>
>> BTW - $allowedPixFileTypes is an array of extensions (.jpg, .jpeg, etc).
>> Not sure if that is the right format for the conditional. Can't test since
>> I can't seem to pull the content type.
>>
>> What am I missing?
>>
>> marc
>>
>>
>> Marc Pinnell
>> 1027 Design
>> PO Box 990872
>> Redding, CA 96099-0872
>> 530.941.4706
>> fax: 866.232.5300
>> www.1027Design.com
>>
>>
>>
>> #############################################################
>>
>> This message is sent to you because you are subscribed to
>>  the mailing list Lasso [hidden email]
>> Official list archives available at http://www.lassotalk.com
>> To unsubscribe, E-mail to: <[hidden email]>
>> Send administrative queries to  <[hidden email]>
>>
>
> #############################################################
>
> This message is sent to you because you are subscribed to
>  the mailing list Lasso [hidden email]
> Official list archives available at http://www.lassotalk.com
> To unsubscribe, E-mail to: <[hidden email]>
> Send administrative queries to  <[hidden email]>

Marc Pinnell
1027 Design
PO Box 990872
Redding, CA 96099-0872
530.941.4706
fax: 866.232.5300
www.1027Design.com



#############################################################

This message is sent to you because you are subscribed to
  the mailing list Lasso [hidden email]
Official list archives available at http://www.lassotalk.com
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: L9: Content Type?

stevepiercy
In reply to this post by Marc Pinnell-3
AFAICT, the file type does not have a ->contenttype method.  Are
you confusing file_uploads with file?

For files that already exist on the system, you could use file
or magic with sys_process to sniff their type.  Most image types
have "image" somewhere in the result.
http://lasso.2283332.n4.nabble.com/File-upload-size-limit-tp3151383p3151386.html

If these images were uploaded by a user, do not trust the file
extension, unless you previously sniffed its content as being an image.

--steve


On 10/21/14 at 10:01 PM, [hidden email] (Marc
Pinnell) pronounced:

>Working with a directory full of images (and a few other
>files). I would like to pull a list of ONLY image files for
>further processing. Seems like this should work, but the
>"contenttype" is throwing an error ( Error Code: -9948 Error
>Msg: Definition Not Found: file->contentType() ):
>
>with fname in dir(#path)->eachFile do {
>
>if(#fname->contenttype >> $allowedPixFileTypes) => {
>#returnFileNames->insert(#path + #fname->name)
>}
>
>}
>
>BTW - $allowedPixFileTypes is an array of extensions (.jpg,
>.jpeg, etc). Not sure if that is the right format for the
>conditional. Can't test since I can't seem to pull the content type.
>
>What am I missing?
>
>marc
>
>
>Marc Pinnell
>1027 Design
>PO Box 990872
>Redding, CA 96099-0872
>530.941.4706
>fax: 866.232.5300
>www.1027Design.com
>
>
>
>#############################################################
>
>This message is sent to you because you are subscribed to
>the mailing list Lasso [hidden email]
>Official list archives available at http://www.lassotalk.com
>To unsubscribe, E-mail to: <[hidden email]>
>Send administrative queries to  <[hidden email]>

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Steve Piercy              Website Builder              Soquel, CA
<[hidden email]>               <http://www.StevePiercy.com/>


#############################################################

This message is sent to you because you are subscribed to
  the mailing list Lasso [hidden email]
Official list archives available at http://www.lassotalk.com
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: L9: Content Type?

Jolle Carlestam-2
In reply to this post by Ke Carlton-3
As in Ke’s suggestion I tend to go for the file extension. But there’s no need to convert the listing to files first. It is faster to examine the name directly. Here’s my suggestion compared to Ke’s:


debug -> activate

local(
        suffixes = (:'jpg', 'jpeg', 'png'),
        path = ’//mypath/',
        returnFileNames
)
debug(’string test') -> timer(1000) => {

        #returnFileNames = (with fname in dir(#path)
        where #suffixes >> #fname -> splitextension('.') -> value
        select #fname) -> asstaticarray
}

debug(’file test') -> timer(1000) => {

        #returnFileNames = (with file in dir(#path) -> eachfile
        let fname = #file -> name
        where #suffixes >> #fname -> splitextension('.') -> value
        select #fname) -> asstaticarray
}


Result:
string test:
micros:1421506.000000
micros_average:1421.506000

file test:
micros:2577845.000000
micros_average:2577.845000

ps, Steve has a point that user uploaded files can’t be trusted. But that is a question to be handled when the file is uploaded.

HDB
Jolle

#############################################################

This message is sent to you because you are subscribed to
  the mailing list Lasso [hidden email]
Official list archives available at http://www.lassotalk.com
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>