Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

missing GetPreSignedURL(request) function in Unity #525

Closed
daves0 opened this issue Jan 8, 2017 · 8 comments
Closed

missing GetPreSignedURL(request) function in Unity #525

daves0 opened this issue Jan 8, 2017 · 8 comments
Labels
bug This issue is a bug. closed-for-staleness module/unity response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. Unity

Comments

@daves0
Copy link

daves0 commented Jan 8, 2017

I'd like to upload to S3 using pre-signed urls from Unity (if I can get past all the SDK bugs in uploading .. sigh ... is anything being done on any of them?) but I get this message when I add a call to GetPreSignedURL (even just pasting in the sample code fails):

Assets/Test.cs(256,34): error CS1061: Type Amazon.S3.AmazonS3Client' does not contain a definition for GetPreSignedURL' and no extension method GetPreSignedURL' of type Amazon.S3.AmazonS3Client' could be found. Are you missing an assembly reference?

I'm not missing an assembly reference .. the method just ain't there. If you look at the source code for the full .Net version, there's stuff in there for it .. but a search in the Mobile SDK doesn't turn up anything except in DynamoDB, where it's using the request to do the work:

this.s3ClientCache.GetClient(this.RegionAsEndpoint).GeneratePreSignedURL(....)

I did searches here on Git using the "This repository" search.

Sorry for the rambling, I've been fighting the SDK and S3 all day and my brain is fried. All I want to do is upload a file, it shouldn't be nearly this hard.

@novavision
Copy link

Any update here? Still can't access this method because it's not exposed

@DanielOS96
Copy link

I'm also having this problem any solution yet?

@feliperb98
Copy link

Same problem here

@ashishdhingra ashishdhingra added bug This issue is a bug. module/unity labels Nov 5, 2020
@feliperb98
Copy link

feliperb98 commented Nov 6, 2020

@ashishdhingra thank you for the labeling, hope the problem can be fixed soon. 👍

@ashishdhingra
Copy link
Contributor

Hi @daves0,

Good afternoon.

Starting with version 3.5 of the AWS SDK for .NET, projects using Unity 2018.1 or later should target the .NET Standard 2.0 release of the SDK. You can find additional information in the developer guide: Unity support and Migrating your Unity application.

Please try using the .NET Standard 2.0 version of the AWS SDK for .NET (version 3.5). Kindly confirm if this is still an issue.

Thanks,
Ashish

@ashishdhingra ashishdhingra added the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Feb 19, 2021
@craftercis
Copy link

craftercis commented Feb 26, 2021

EDIT: Hello. I have this script working in the editor. When i type the name of the S3 file in a Inputfield and I press a button the URL is set to another inputfield so that i can copy and paste it to google. But when I build it to Android it crashes when i press the button. Who can help me?

`using Amazon;
using Amazon.S3;
using Amazon.S3.Model;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class Test : MonoBehaviour
{
private const string bucketName = "***";
// Specify your bucket region (an example region is shown).
private static readonly RegionEndpoint bucketRegion = RegionEndpoint.EUWest3;
private static IAmazonS3 s3Client;

private static InputField setNameField;
private static InputField setURLField;

public void ButtonClick()
{
    setNameField = GameObject.Find("Set Name InputField").GetComponent<InputField>();
    setURLField = GameObject.Find("Set URL InputField").GetComponent<InputField>();
    Main();
}

public void Main()
{
    s3Client = new AmazonS3Client(bucketRegion);
    string urlString = GeneratePreSignedURL();
    Console.WriteLine(urlString);
    Console.Read();
}
static string GeneratePreSignedURL()
{
    string urlString = "";
    try
    {
        //ServerSideEncryptionMethod ssem = new ServerSideEncryptionMethod("AWSKMS");
        GetPreSignedUrlRequest request1 = new GetPreSignedUrlRequest
        {
            BucketName = bucketName,
            Key = setNameField.text,
            Expires = DateTime.Now.AddSeconds(10),
            Verb = 0,
            //ServerSideEncryptionKeyManagementServiceKeyId = "some-value",
            //ServerSideEncryptionMethod = ServerSideEncryptionMethod.AWSKMS
        };
        urlString = s3Client.GetPreSignedURL(request1);
    }
    catch (AmazonS3Exception e)
    {
        Console.WriteLine("Error encountered on server. Message:'{0}' when writing an object", e.Message);
    }
    catch (Exception e)
    {
        Console.WriteLine("Unknown encountered on server. Message:'{0}' when writing an object", e.Message);
    }
    setURLField.text = urlString;
    Debug.Log(urlString);
    return urlString;
}

}
`

@craftercis
Copy link

EDIT: Hello. I have this script working in the editor. When i type the name of the S3 file in a Inputfield and I press a button the URL is set to another inputfield so that i can copy and paste it to google. But when I build it to Android it crashes when i press the button. Who can help me?

`using Amazon;
using Amazon.S3;
using Amazon.S3.Model;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class Test : MonoBehaviour
{
private const string bucketName = "***";
// Specify your bucket region (an example region is shown).
private static readonly RegionEndpoint bucketRegion = RegionEndpoint.EUWest3;
private static IAmazonS3 s3Client;

private static InputField setNameField;
private static InputField setURLField;

public void ButtonClick()
{
    setNameField = GameObject.Find("Set Name InputField").GetComponent<InputField>();
    setURLField = GameObject.Find("Set URL InputField").GetComponent<InputField>();
    Main();
}

public void Main()
{
    s3Client = new AmazonS3Client(bucketRegion);
    string urlString = GeneratePreSignedURL();
    Console.WriteLine(urlString);
    Console.Read();
}
static string GeneratePreSignedURL()
{
    string urlString = "";
    try
    {
        //ServerSideEncryptionMethod ssem = new ServerSideEncryptionMethod("AWSKMS");
        GetPreSignedUrlRequest request1 = new GetPreSignedUrlRequest
        {
            BucketName = bucketName,
            Key = setNameField.text,
            Expires = DateTime.Now.AddSeconds(10),
            Verb = 0,
            //ServerSideEncryptionKeyManagementServiceKeyId = "some-value",
            //ServerSideEncryptionMethod = ServerSideEncryptionMethod.AWSKMS
        };
        urlString = s3Client.GetPreSignedURL(request1);
    }
    catch (AmazonS3Exception e)
    {
        Console.WriteLine("Error encountered on server. Message:'{0}' when writing an object", e.Message);
    }
    catch (Exception e)
    {
        Console.WriteLine("Unknown encountered on server. Message:'{0}' when writing an object", e.Message);
    }
    setURLField.text = urlString;
    Debug.Log(urlString);
    return urlString;
}

}
`

I solved it. I had to put my accessKey and secretKey together with the Region in AmazonS3Client.

If someone later also has this problem here is the code.

`using Amazon;
using Amazon.Runtime;
using Amazon.S3;
using Amazon.S3.Model;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Net;
using UnityEngine;
using UnityEngine.UI;

public class TestGenerate : MonoBehaviour
{

public static InputField setUrlField;

public void Start()
{
    //This is the InputField where you can copy the URL from.
    setUrlField = GameObject.Find("Set URL InputField").GetComponent<InputField>();
}

public static string GetContents(string path)
{
    HttpWebRequest request = HttpWebRequest.Create(path) as HttpWebRequest;
    HttpWebResponse response = request.GetResponse() as HttpWebResponse;

    using (Stream stream = response.GetResponseStream())
    using (StreamReader reader = new StreamReader(stream))
    {
        Debug.Log(path);
        setUrlField.text = path;
        return reader.ReadToEnd();
    }
}

public void Test()
{
    var credentials = new BasicAWSCredentials("YOUR ACCESSKEY", "YOUR SECRET KEY");
    // Create a client. Set the region endpoint to your region!
    AmazonS3Client client = new AmazonS3Client(credentials, RegionEndpoint.EUWest3);

    // Create a CopyObject request
    GetPreSignedUrlRequest request = new GetPreSignedUrlRequest
    {
        BucketName = "YOUR BUCKET NAME",
        Key = "YOUR OBJECT KEY",
        Expires = DateTime.UtcNow.AddSeconds(10)
    };

    // Get path for request
    string path = client.GetPreSignedURL(request);

    // Test by getting contents
    string contents = GetContents(path);
}

}
`

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Feb 27, 2021
@ashishdhingra ashishdhingra added the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Mar 9, 2021
@github-actions
Copy link

This issue has not recieved a response in 2 weeks. If you want to keep this issue open, please just leave a comment below and auto-close will be canceled.

@github-actions github-actions bot added the closing-soon This issue will automatically close in 4 days unless further comments are made. label Mar 13, 2021
@github-actions github-actions bot added closed-for-staleness and removed closing-soon This issue will automatically close in 4 days unless further comments are made. labels Mar 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. closed-for-staleness module/unity response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. Unity
Projects
None yet
Development

No branches or pull requests

9 participants