Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by Kiloblargh · Sep 07, 2012 at 01:15 AM · wwwapiimages

How can I upload a PNG to imgur and save its URL?

I have a screenshot I want to post to Facebook but I can only post a link to it. So I want to upload it to imgur, automatically from a script in Unity, and return the URL directly linking to the image.

They have an API page but I can't figure out how to translate that into a WWW call from Unity. It seems like it should be a lot simpler than it looks from their examples.

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ByteSheep · Sep 07, 2012 at 01:45 AM 0
Share

The javascript upload script on the API page seems to be creating a form object containing the image info, which is then sent to a upload.json file on the imgur domain. To send the image using this script you would probably first have to create a php file containing the javascript as well as some php to check for any variables set in the url to your php file. I'm not sure how you are sending your image to your webpage. eg are you sending all the actual source code of the image? Unity communicates with your webpage through sending info in the url. To do what you are attempting will as far as I know require you to send the image data not directly to imgur, but rather to a webpage created by you containing the upload script. The upload script would then receive the image info from unity and send it to the imgur API. Sorry I can't be of more help, but I've never tried uploading an image through unity.. just my thoughts on how one might go about it ;)

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by by0log1c · Sep 07, 2012 at 01:51 AM

I'll admit I haven't read the full API but only peek at the ImgurExample class from the page you linked.

What they do is they take in an image path, read its content as byte[], then convert it to a base64 string. Your image is now effectively a string of text which can be turned back into an image (think: serialization). They then create a standard POST call to the imgur url and pass it the text, imgur then return some text. I assume that imgur convert your image string back into an image and that the text it returns is the final image url you need. Using it within Unity should be fairly easy.

The first way I can think of is to ... use the very example provided - that is valid C# code and I assume it'll work out-of-the-box. I'm not 100% sure that Mono provides the System.Net namespace, but they probably do - and unless you plan to go crossplatform, you could still workaround the issue by importing your .NET dll (assuming you're on Windows).

The second way I can think of is to use only Unity stuff, that is assured to work. You can use the first half of the example to convert your image to text. Once you have the imgur url, your image-text - and apparently an imgur api key - you will use the WWWForm class to create your own POST. That form should include 2 text fields named 'image' and 'key' and holding the relevant value. Pass that WWWForm through a WWW aimed at the imgur url and yield that. Once its all done, www.text should hold the final url.

Disclaimer: I assumed all that stuff from looking at the example one(1) minute, I might be totally off.

EDIT: if you had access to webserver space, it'd also be easy to create a php or asp.net script - but in the end, that's what imgur does, you still have to do the unity side stuff and it'd be pretty much the same.

EDIT2: no idea why the System.Net is an url, its not me who set it.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
-1

Answer by tata22560 · Oct 28, 2017 at 10:38 PM

link text

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

10 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Calling API via proxy 0 Answers

Is pulling and parsing XML data from 3rd party API call possible? 1 Answer

Question: Is it possible to create an image out of an HTML canvas in unity using c#? 0 Answers

Use the data received from WWW in UI 1 Answer

WWW class and HTTP Headers 3 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges