IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Spring Java Discussion :

API DropBox et Spring


Sujet :

Spring Java

  1. #1
    Nouveau membre du Club
    Femme Profil pro
    Étudiant
    Inscrit en
    Avril 2014
    Messages
    46
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 32
    Localisation : France, Hauts de Seine (Île de France)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Enseignement

    Informations forums :
    Inscription : Avril 2014
    Messages : 46
    Points : 29
    Points
    29
    Par défaut API DropBox et Spring
    Bonjour à tous je souhaite upload des fichiers via l'API DropBox sachant que j'utilise Spring (spring security aussi) mais j'obtiens l'erreur suivante :

    Etat HTTP 405 - Request method 'POST' not supported

    Pouvez-vous me guider s'il vous plaît, je ne comprends pas ce qu'il ne va pas...

    Ma méthode dans le controller:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
     
     
    @RequestMapping(value = "/uploadFile", method = RequestMethod.POST)
        public void uploadFile(@RequestParam("file") File file) throws IOException, DbxException{
            final String APP_KEY = "MON CODE";
            final String APP_SECRET = "MON CODE";
     
            DbxAppInfo appInfo = new DbxAppInfo(APP_KEY, APP_SECRET);
     
            DbxRequestConfig config = new DbxRequestConfig(
                    "syndic/1.0", Locale.getDefault().toString());
            DbxWebAuthNoRedirect webAuth = new DbxWebAuthNoRedirect(config, appInfo);
     
            String authorizeUrl = webAuth.start();
            System.out.println("1. Go to: " + authorizeUrl);
            System.out.println("2. Click \"Allow\" (you might have to log in first)");
            System.out.println("3. Copy the authorization code.");
     
            String code = new BufferedReader(new InputStreamReader(System.in)).readLine().trim();
     
            // This will fail if the user enters an invalid authorization code.
            DbxAuthFinish authFinish = webAuth.finish(code);
            String accessToken = authFinish.accessToken;
     
            DbxClient client = new DbxClient(config, accessToken);
            System.out.println("Linked account: " + client.getAccountInfo().displayName);
     
            File inputFile = file;
            FileInputStream inputStream = new FileInputStream(inputFile);
            try {
                DbxEntry.File uploadedFile = client.uploadFile("/magnum-opus.txt",
                        DbxWriteMode.add(), inputFile.length(), inputStream);
                System.out.println("Uploaded: " + uploadedFile.toString());
            } finally {
                inputStream.close();
            }
        }
    Mon formulaire dans la JSP:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
     
    <body>
     
    <div class="container">
     
     
        <form:form method="POST" enctype="multipart/form-data">
     
            <form:errors path="*" cssClass="errorblock" element="div" />
     
            Please select a file to upload : <input type="file" name="file" />
            <input type="submit" value="upload" />
    		<span><form:errors path="file" cssClass="error" />
    		</span>
     
        </form:form>
     
    </div>
     
    </body>

  2. #2
    Rédacteur/Modérateur
    Avatar de andry.aime
    Homme Profil pro
    Inscrit en
    Septembre 2007
    Messages
    8 391
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Ile Maurice

    Informations forums :
    Inscription : Septembre 2007
    Messages : 8 391
    Points : 15 059
    Points
    15 059
    Par défaut
    Bonjour,

    Code jsp : Sélectionner tout - Visualiser dans une fenêtre à part
    <form:form method="POST" enctype="multipart/form-data" action="/uploadFile">

    A+.

  3. #3
    Nouveau membre du Club
    Femme Profil pro
    Étudiant
    Inscrit en
    Avril 2014
    Messages
    46
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 32
    Localisation : France, Hauts de Seine (Île de France)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Enseignement

    Informations forums :
    Inscription : Avril 2014
    Messages : 46
    Points : 29
    Points
    29
    Par défaut
    Bonjour,

    Je vous remercie pour votre réponse.

    Lors que je remplace

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    <form:form method="POST" enctype="multipart/form-data">
    par

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    <form:form method="POST" enctype="multipart/form-data" action="/uploadFile">
    J'obtiens cette erreur Etat HTTP 404 - /uploadFile

    Le fichier ne se charge pas...Avez vous une autre idée s'il vous plaît?

  4. #4
    Rédacteur/Modérateur
    Avatar de andry.aime
    Homme Profil pro
    Inscrit en
    Septembre 2007
    Messages
    8 391
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Ile Maurice

    Informations forums :
    Inscription : Septembre 2007
    Messages : 8 391
    Points : 15 059
    Points
    15 059
    Par défaut
    Peut-on voir le code de ton controller en complet et quel version de spring tu utilises?

  5. #5
    Nouveau membre du Club
    Femme Profil pro
    Étudiant
    Inscrit en
    Avril 2014
    Messages
    46
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 32
    Localisation : France, Hauts de Seine (Île de France)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Enseignement

    Informations forums :
    Inscription : Avril 2014
    Messages : 46
    Points : 29
    Points
    29
    Par défaut
    J'utilise la version 4.0.2 de Spring.

    Mon controller :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
     
    package org.syndic.client.web.home.controller;
     
    import fr.upond.syndic.repo.model.common.Address;
    import fr.upond.syndic.repo.model.common.Condo;
    import fr.upond.syndic.repo.model.common.Lot;
    import fr.upond.syndic.repo.model.common.Provider;
    import fr.upond.syndic.repo.model.event.Event;
    import fr.upond.syndic.service.IManager;
    import org.apache.commons.logging.Log;
    import org.apache.commons.logging.LogFactory;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Controller;
    import org.springframework.transaction.annotation.Transactional;
    import org.springframework.ui.ModelMap;
    import org.springframework.web.bind.annotation.ModelAttribute;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RequestMethod;
    import org.springframework.web.bind.annotation.RequestParam;
     
    import fr.upond.syndic.repository.user.UserDaoImpl;
    import org.springframework.web.servlet.view.RedirectView;
    import org.syndic.client.web.command.CondoCommand;
    import org.syndic.client.web.command.ProviderCommand;
     
     
    import java.util.HashSet;
    import java.util.Map;
    import java.util.Set;
     
     
    import com.dropbox.core.*;
    import java.io.*;
    import java.util.Locale;
     
     
    @Controller
    @Transactional
    public class Home {
     
    private static final Log logger = LogFactory.getLog(Home.class);
     
    	@Autowired
    	private IManager<Object> manager;
    	@Autowired
    	private UserDaoImpl userDao;
     
    	public void setManager(IManager<Object> manager) {
    		this.manager = manager;
    	}
    	public void setUserDao(UserDaoImpl userDao) {
    		this.userDao = userDao;
    	}
     
            @RequestMapping(value = "/getformaddcondo", method = RequestMethod.GET)
    	public String getFormAddCondo(Map<String,Object> model) {
    		logger.info("==== Get Form Condo =====");
    		model.put("condoCommand", new CondoCommand());
    		return "addCondoPage";
    	}
     
            @RequestMapping(value = "/addcondo", method = RequestMethod.POST)
    	public String addCondo(@ModelAttribute("condoCommand") CondoCommand condoCommand) {
    		logger.info("== uri: /addcondo ==");
     
    		Address address = new Address(condoCommand.getNumAddressStart()+", "+condoCommand.getNumAddressEnd(),
    				condoCommand.getTypeAddress(), condoCommand.getStreet(),condoCommand.getCity(), condoCommand.getZipcode(),
    				condoCommand.getCountry(), condoCommand.getPlaceName());
    		Lot lot = new Lot(Integer.parseInt(condoCommand.getCodeLot()), condoCommand.getTypeLot(),
    				Integer.parseInt(condoCommand.getFloorLot()),
    				Double.parseDouble(condoCommand.getAreaLot()), Double.parseDouble(condoCommand.getPart()));
    		Set<Lot> setLot = new HashSet<Lot>(0);
    		setLot.add(lot);
    		Condo condo = new Condo(condoCommand.getName(), Double.parseDouble(condoCommand.getAreaCondo()), address);
    		condo.setLot(setLot);
     
    		this.manager.add(condo);
     
    		return "welcomeSyndicPage";
    	}
     
     
             // + d'autres méthodes du même type
     
     
     @RequestMapping(value = "/getformupload", method = RequestMethod.GET)
        public String getFormUpload(Map<String,Object> model) {
            logger.info("==== Get Form Upload =====");
     
            return "uploadPage";
        }
     
        @RequestMapping(value = "/uploadFile", method = RequestMethod.POST)
        public void uploadFile(@RequestParam("file") File file) throws IOException, DbxException{
            final String APP_KEY = "64foz0ixb66kp79";
            final String APP_SECRET = "kcqmxhagcs764jl";
     
            DbxAppInfo appInfo = new DbxAppInfo(APP_KEY, APP_SECRET);
     
            DbxRequestConfig config = new DbxRequestConfig(
                    "syndic/1.0", Locale.getDefault().toString());
            DbxWebAuthNoRedirect webAuth = new DbxWebAuthNoRedirect(config, appInfo);
     
            String authorizeUrl = webAuth.start();
            System.out.println("1. Go to: " + authorizeUrl);
            System.out.println("2. Click \"Allow\" (you might have to log in first)");
            System.out.println("3. Copy the authorization code.");
     
            String code = new BufferedReader(new InputStreamReader(System.in)).readLine().trim();
     
            // This will fail if the user enters an invalid authorization code.
            DbxAuthFinish authFinish = webAuth.finish(code);
            String accessToken = authFinish.accessToken;
     
            DbxClient client = new DbxClient(config, accessToken);
            System.out.println("Linked account: " + client.getAccountInfo().displayName);
     
            File inputFile = file;
            FileInputStream inputStream = new FileInputStream(inputFile);
            try {
                DbxEntry.File uploadedFile = client.uploadFile("/magnum-opus.txt",
                        DbxWriteMode.add(), inputFile.length(), inputStream);
                System.out.println("Uploaded: " + uploadedFile.toString());
            } finally {
                inputStream.close();
            }
        }
    Dans mon pom.xml j'ai bien ajouté la dépendance de dropbox

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
          <dependency>
              <groupId>com.dropbox.core</groupId>
              <artifactId>dropbox-core-sdk</artifactId>
              <version>[1.7,1.8)</version>
          </dependency>

  6. #6
    Nouveau membre du Club
    Femme Profil pro
    Étudiant
    Inscrit en
    Avril 2014
    Messages
    46
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 32
    Localisation : France, Hauts de Seine (Île de France)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Enseignement

    Informations forums :
    Inscription : Avril 2014
    Messages : 46
    Points : 29
    Points
    29
    Par défaut
    Bonjour,

    Personne n'a d'idée?

Discussions similaires

  1. PHP et API Dropbox
    Par BlackAlpha dans le forum Langage
    Réponses: 13
    Dernier message: 02/05/2014, 08h04
  2. Utilisation de l'API Dropbox
    Par Nico02 dans le forum Général Java
    Réponses: 2
    Dernier message: 05/03/2014, 18h30
  3. [DropBox] Utilisation de l'API Dropbox
    Par Nico02 dans le forum Stockage
    Réponses: 0
    Dernier message: 18/02/2014, 16h14
  4. Methode REST API Dropbox, SkyDrive
    Par laurentbeatles dans le forum API standards et tierces
    Réponses: 3
    Dernier message: 04/02/2013, 16h12
  5. API DropBox et Eclipse
    Par gridsof dans le forum API standards et tierces
    Réponses: 0
    Dernier message: 05/12/2011, 16h29

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo