473,386 Members | 1,943 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Re: String Literal to Blob

Victor Subervi wrote:
in line...

On Fri, Apr 11, 2008 at 2:05 PM, Steve Holden <st***@holdenweb.com
<mailto:st***@holdenweb.com>wrote:

Victor Subervi wrote:
I have worked on this many hours a day for two weeks. If there is an
easier way to do it, just take a minute or two and point it out. Have
you heard of the Law of Diminishing Returns? I have passed it
long ago.
I no longer want to waste time trying to guess at what you are
trying to
tell me.
Victor
>
On Fri, Apr 11, 2008 at 8:55 AM, Steve Holden
<st***@holdenweb.com <mailto:st***@holdenweb.com>
<mailto:st***@holdenweb.com <mailto:st***@holdenweb.com>>wrote:
Where you have

content = col_fields[0][14].tostring()
pic = "tmp" + str(i) + ".jpg"
img = open(pic, "w")
img.write(content)
print '<img src="%s"><br /><br />' % pic
img.close()

instead write

print content
Like this, I presume?
Yes. You might need to use content.tostring() - I am not familiar with
MySQL blobs.
img = open(pic, "w")
img.write(content)
print '<td><input type="hidden" name="%s"' % str(x), '
value="%s">' % pic
print content
# print '<img src="%s"><br /><br /></td>\n' % pic
Does not work _at_all LOL. You will recall, also, that you once gave me
a line similar to the one commented out (but without writing then
opening the file). THAT did not work, either. So now do you see why I am
frustrated??

Then browse to the URL this program serves and you will see the image
(assuming you are still sending the image/jpeg content type).
Well, as I mentioned before, I am sending text/html because the page,
like almost all web pages, has a whole lot more content than just
images. Or, perhaps you are suggesting I build my pages in frames, and
have a frame for every image. Unsightly!
Dear Victor:

If you cannot understand, after being told several times by different
people, that pages with images in them are achieved by multiple HTTP
requests, then there is little I can do to help you.
>
Once you
can see the image, THEN you can write a page that refers to it. Until
you start serving the image (NOT pseudo-html with image data embedded in
it) nothing else will work.
My solution works just fine, thank you. It is inelegant. But it now
appears to me, and I dare say rather clearly, that this inelegance is
the fault of python itself. Perhaps this should be brought to Guido´s
attention.
Victor
You can say it as clearly as you like, but if you say it too loudly you
will make a laughing stock of yourself.

You surely don't think that a language that supports Zope, TurboGears,
Pylons and Django (to name but the first four that come to mind) is
unsuitable for web programming?

Please, do yourself a big favor and persist with this until you
understand what you are doing wrong and how to serve dynamic images. It
appears that the learning may be painful, but I guarantee it will be
worthwhile.

regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/
Jun 27 '08 #1
7 2200
On Apr 12, 2:44 pm, Steve Holden <st...@holdenweb.comwrote:
Victor Subervi wrote:
in line...
On Fri, Apr 11, 2008 at 2:05 PM, Steve Holden <st...@holdenweb.com
<mailto:st...@holdenweb.com>wrote:
Victor Subervi wrote:
I have worked on this many hours a day for two weeks. If there isan
easier way to do it, just take a minute or two and point it out. Have
you heard of the Law of Diminishing Returns? I have passed it
long ago.
I no longer want to waste time trying to guess at what you are
trying to
tell me.
Victor
On Fri, Apr 11, 2008 at 8:55 AM, Steve Holden
<st...@holdenweb.com <mailto:st...@holdenweb.com>
<mailto:st...@holdenweb.com <mailto:st...@holdenweb.com>>wrote:
Where you have
content = col_fields[0][14].tostring()
pic = "tmp" + str(i) + ".jpg"
img = open(pic, "w")
img.write(content)
print '<img src="%s"><br /><br />' % pic
img.close()
instead write
print content
Like this, I presume?

Yes. You might need to use content.tostring() - I am not familiar with
MySQL blobs.
img = open(pic, "w")
img.write(content)
print '<td><input type="hidden" name="%s"' % str(x), '
value="%s">' % pic
print content
# print '<img src="%s"><br /><br /></td>\n' % pic
Does not work _at_all LOL. You will recall, also, that you once gave me
a line similar to the one commented out (but without writing then
opening the file). THAT did not work, either. So now do you see why I am
frustrated??
Then browse to the URL this program serves and you will see the image
(assuming you are still sending the image/jpeg content type).
Well, as I mentioned before, I am sending text/html because the page,
like almost all web pages, has a whole lot more content than just
images. Or, perhaps you are suggesting I build my pages in frames, and
have a frame for every image. Unsightly!

Dear Victor:

If you cannot understand, after being told several times by different
people, that pages with images in them are achieved by multiple HTTP
requests, then there is little I can do to help you.
Once you
can see the image, THEN you can write a page that refers to it. Until
you start serving the image (NOT pseudo-html with image data embedded in
it) nothing else will work.
My solution works just fine, thank you. It is inelegant. But it now
appears to me, and I dare say rather clearly, that this inelegance is
the fault of python itself. Perhaps this should be brought to Guido´s
attention.
Victor

You can say it as clearly as you like, but if you say it too loudly you
will make a laughing stock of yourself.

You surely don't think that a language that supports Zope, TurboGears,
Pylons and Django (to name but the first four that come to mind) is
unsuitable for web programming?

Please, do yourself a big favor and persist with this until you
understand what you are doing wrong and how to serve dynamic images. It
appears that the learning may be painful, but I guarantee it will be
worthwhile.

regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/
There _is_ a way to embed image data in HTML that is supported by
every major browser. It is ugly. Using the RFC 2397 (http://
www.ietf.org/rfc/rfc2397) spec for data URLs you could go

'<img src="data:image/jpg;base64,%s">' % base64.b64encode(image_data)

Obviously you need to import the base64 module somewhere in your code
and base64-encoded data is about a third larger than it would be
otherwise, so embedding anything particularly large is going to be a
huge pain and affect page load times pretty badly.
Jun 27 '08 #2
En Sat, 12 Apr 2008 22:14:31 -0300, Jason Scheirer
<ja************@gmail.comescribió:
On Apr 12, 2:44 pm, Steve Holden <st...@holdenweb.comwrote:
>Victor Subervi wrote:
Well, as I mentioned before, I am sending text/html because the page,
like almost all web pages, has a whole lot more content than just
images. Or, perhaps you are suggesting I build my pages in frames, and
have a frame for every image. Unsightly!

Dear Victor:

If you cannot understand, after being told several times by different
people, that pages with images in them are achieved by multiple HTTP
requests, then there is little I can do to help you.
[...]
Please, do yourself a big favor and persist with this until you
understand what you are doing wrong and how to serve dynamic images. It
appears that the learning may be painful, but I guarantee it will be
worthwhile.

There _is_ a way to embed image data in HTML that is supported by
every major browser. It is ugly. Using the RFC 2397 (http://
www.ietf.org/rfc/rfc2397) spec for data URLs you could go

'<img src="data:image/jpg;base64,%s">' % base64.b64encode(image_data)
Another alternative would be to generate a multipart/related document, but
I think the OP will gain a lot more understanding the simple cases than
using those esoteric features.

--
Gabriel Genellina

Jun 27 '08 #3
En Sat, 12 Apr 2008 22:14:31 -0300, Jason Scheirer
<ja************@gmail.comescribió:
On Apr 12, 2:44 pm, Steve Holden <st...@holdenweb.comwrote:
>Victor Subervi wrote:
Well, as I mentioned before, I am sending text/html because the page,
like almost all web pages, has a whole lot more content than just
images. Or, perhaps you are suggesting I build my pages in frames, and
have a frame for every image. Unsightly!

Dear Victor:

If you cannot understand, after being told several times by different
people, that pages with images in them are achieved by multiple HTTP
requests, then there is little I can do to help you.
[...]
Please, do yourself a big favor and persist with this until you
understand what you are doing wrong and how to serve dynamic images. It
appears that the learning may be painful, but I guarantee it will be
worthwhile.

There _is_ a way to embed image data in HTML that is supported by
every major browser. It is ugly. Using the RFC 2397 (http://
www.ietf.org/rfc/rfc2397) spec for data URLs you could go

'<img src="data:image/jpg;base64,%s">' % base64.b64encode(image_data)
Another alternative would be to generate a multipart/related document, but
I think the OP will gain a lot more understanding the simple cases than
using those esoteric features.

--
Gabriel Genellina

Jun 27 '08 #4
Jason Scheirer wrote:
[...]
>
There _is_ a way to embed image data in HTML that is supported by
every major browser. It is ugly. Using the RFC 2397 (http://
www.ietf.org/rfc/rfc2397) spec for data URLs you could go

'<img src="data:image/jpg;base64,%s">' % base64.b64encode(image_data)

Obviously you need to import the base64 module somewhere in your code
and base64-encoded data is about a third larger than it would be
otherwise, so embedding anything particularly large is going to be a
huge pain and affect page load times pretty badly.
This is hardly likely to help someone who hasn't yet grasped the concept
of referencing graphics and prefers to write database output to disk to
serve it statically. But who knows, maybe it will ...

regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/

Jun 27 '08 #5
Victor Subervi wrote:
Thanks to all, especially Gabriel. The base64 is a good idea, but you
state a definite problem. I will look at your code at home
(offline)...thank you very much! It looks like the kicker is this line here:

<img src='getpic.py?id=%d' alt='%s'>" % (picid, cgi.escape(title))

Now, why didn´t you share that before????? I can see how calling a
separate script like that would work! Again, you should have shared that
before. How was I to think of that clever trick from the bare
information you gave me earlier??

Steve, thank you for all your help, but do overcome your temper :))
Victor:

I'm glad the penny finally dropped. You may have been treated to a
modest display of exasperation, but please be assured you have not yet
seen anything remotely like temper from me :-)

The thing I found difficult to understand was, given your assertion on
April 9 "But I am persistent. And I have built dozens of Web site with
images" that you hadn't already addressed these issues. I was clearly
assuming too much knowledge on your part.

Hooray! You got it! Your persistence finally paid off, well done!

regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/
Jun 27 '08 #6
En Mon, 14 Apr 2008 11:03:54 -0300, Steve Holden <st***@holdenweb.com>
escribió:
Victor Subervi wrote:
>Thanks to all, especially Gabriel. [...]
Steve, thank you for all your help, but do overcome your temper :))

I'm glad the penny finally dropped. You may have been treated to a
modest display of exasperation, but please be assured you have not yet
seen anything remotely like temper from me :-)
And I'm glad to see that you finally "got it", too!

--
Gabriel Genellina

Jun 27 '08 #7
It is published. On comp.lang.python. Google groups has it, so google
(search) will find it.

Cheers,
Cliff
On Tue, 2008-04-15 at 17:04 +0200, Victor Subervi wrote:
Gabriel;

That's really nice code you wrote. I will rewrite my app accordingly,
after I catch a breather! Say, would you please publish this
somewhere? Why should I write a howto on this and credit you when all
I would be doing is republishing (plagerizing) what you published?
Please insert these keywords: mysql, image, python, mysqldb and maybe
picture and photo (you already have photo). Call it something like
"MySQL/Python Tutorial for Posting and Retrieving Images / Photo
Album". I ask you to do this because I scoured google looking for just
what you've provided and it simply isn't out there. At all. There are
nice howto's in php. Please post this for those interested in python,
somewhere like the cookbook.

Thanks,

Victor

On Tue, Apr 15, 2008 at 3:23 AM, Gabriel Genellina
<ga*******@yahoo.com.arwrote:
En Mon, 14 Apr 2008 11:03:54 -0300, Steve Holden
<st***@holdenweb.com>
escribió:
Victor Subervi wrote:
>Thanks to all, especially Gabriel. [...]
>Steve, thank you for all your help, but do overcome your
temper :))
>
I'm glad the penny finally dropped. You may have been
treated to a
modest display of exasperation, but please be assured you
have not yet
seen anything remotely like temper from me :-)


And I'm glad to see that you finally "got it", too!

--
Gabriel Genellina

--

http://mail.python.org/mailman/listinfo/python-list

--
Oook,
J. Cliff Dyer
Carolina Digital Library and Archives
UNC Chapel Hill

Jun 27 '08 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: Don Starr | last post by:
When applied to a string literal, is the sizeof operator supposed to return the size of the string (including nul), or the size of a pointer? For example, assuming a char is 1 byte and a char *...
17
by: Olivier Bellemare | last post by:
I've tried to make a function that returns the middle of a string. For example: strmid("this is a text",6,4); would return "is a". Here is my code: char *strmid(char *texte, int depart,...
7
by: al | last post by:
char s = "This string literal"; or char *s= "This string literal"; Both define a string literal. Both suppose to be read-only and not to be modified according to Standard. And both have...
4
by: songkv | last post by:
Hi, I am trying to reassign an array of char to a string literal by calling a function. In the function I use pointer-to-pointer since I want to reassign the "string array pointer" to the string...
8
by: junky_fellow | last post by:
what would be the output for the following piece of code ? if ( "hello" == "hello" ) printf("True\n"); else printf("False\n"); What is the reason for that ?
5
by: John Baro | last post by:
I have a richtextbox which I want the "literal" rtf of. richtextbox.rtf returns {\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033\\uc1 }\r\n\0 when i put this into a string I get...
2
by: martin | last post by:
Hi, I have blob field in my database. I am retrieveing the field through a stored procedure and the execute scalar method. I would like to cast resulting "byte" field to a string. I am using...
20
by: Guadala Harry | last post by:
In an ASCX, I have a Literal control into which I inject a at runtime. litInjectedContent.Text = dataClass.GetHTMLSnippetFromDB(someID); This works great as long as the contains just...
5
by: polas | last post by:
Good morning, I have a quick question to clear up some confusion in my mind. I understand that using a string literal in a declaration such as char *p = "string literal" declares a pointer to...
4
by: zaimoni | last post by:
I've already calculated that the following are valid and should not error, as both just end up with the character literal 'A' being their control expression. The unspecified value of the char*...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.